question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Price Reading From xlsx file

See original GitHub issue

Before submitting an issue, please fill this out

Is this a:

  • Issue with the OpenXml library
  • Question on library usage

If you have answered that this is a question, please ask it on StackOverflow instead of here. This issue tracker is meant to track product issues while StackOverflow excels at answering questions

---------------- Remove this line and above before posting ----------------

Description

I am uploading some products in excel, There are only two columns one is name other is price. I have read rows from excel as you suggested, also I added a method reading with cell index because when a cell is null, it was sliding.

I keep the inner text from the cell if the cell has a datatype

`
string value = cell?.InnerText;

case CellValues.SharedString: value = stringTablePart.SharedStringTable.ChildElements[Int32.Parse(value)].InnerText?.Trim(); break;

return value; ` I get the value like that, everything is ok except price. It changes the signs. firstly removes all dots, then replaces the comma to dot ex1. value from excel 1.200.000,50 -> reads like 12000000.5

so dot and comma comes from culture number seperator settings, culture and cultureUI and current thread culture and ui set as tr-TR because tr culture has . for group seperator and comma for decimal seperator.

Why is this excel reading like that?

Information

  • .NET Target: (.Net 5)
  • DocumentFormat.OpenXml Version: (ie 2.13.0)

Repro

// Please add a self-contained, minimum viable repro of the issue.
// If you require external resources, please provide a gist or GitHub repro
// An Xunit style test is preferred, but a console application would work too.

Observed

value saved in excel 1.500,70 read like 1500.7

Expected

it should read the same as how is written. Because the convert working with culture settings, this is a string value and I will parse this to decimal. (1500.7) this is converted as (15007) because . is group separetor.

Please add your expected behavior here.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
ThomasBarnekowcommented, Apr 27, 2022

Please share the following:

  • The Open XML markup that shows what is stored in the SpreadsheetDocument
  • The C# code that shows how you read that Open XML and produce the formatted number

You need to understand that the Open XML SDK just gives you access to the raw data stored in the various XML files that together form a document (e.g., Workbook). So, you will be able to see a raw floating-point number in the invariant culture (e.g., 1500.7). You will also see the format specifications that might have been entered in Excel. However, the SDK does not perform any formatting for you. Instead, you would have to read the raw number and the format specifications, interpret the format specifications and format the number accordingly if you need that.

0reactions
caglarsarikayacommented, Apr 28, 2022

Okay but I tried all formatting types in excel, I created rows with all kinds of formatting types with the 1.200,55 value and all of the formatting types did not change the read data 😕 but okay thanks, you said it’s not an issue, maybe I missed something. I am closing this now, thanks for your time

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pandas read_excel() - Reading Excel File in Python
We can use the pandas module read_excel() function to read the excel file data into a DataFrame object. If you look at an...
Read more >
Fast way to read xlsx files into R
readxl might be faster, but with significant costs: it only analyzes the first 1000 rows to determine the column types. This is suboptimal, ......
Read more >
Reading Excel File in Python – Importing an ...
Reading Excel File with Pandas​​ Once the installation is done, make a python file using the below-given script for reading the sales. xlsx...
Read more >
Reading and Importing Excel Files Into R With readxl
In this article, learn how import excel files into R with the readxl library.
Read more >
Look Up Data in an Excel (XLSX) File
The following DataWeave script reads an XLSX file and returns filtered data from it. It assumes that a spreadsheet named ourBugs.xlsx contains data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found