Price Reading From xlsx file
See original GitHub issueBefore 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:
- Created a year ago
- Comments:8
Please share the following:
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.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