Quantcast
Channel: EPPlus Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 2262

Commented Unassigned: Cannot read cell double value when it is incorrectly formatted as Date in the source sheet [15436]

$
0
0
We can reproduce the issue by creating a simple spreadsheet with a cell value 19120072 being formatted as M/d/yyyy.

When you open the sheet by excel you will see it as ###########. That means it is not a proper OADate value. However if you use VBA code Range("...").Value2 , you will still see the numerical value.

On EPPlus, if you read the cell the Value property is an empty string, and there is simply no way to get back the original value even I tried applying a proper format to the cell within the same EPPlus session.

I understand that I can modify the sheet manually and read it again but it is an overnight batch job which causing lots more production support overhead.

Thanks






Comments: To be clear I modified the ExcelWorksheet SetValueFromXml() method (line 1415 to 1457) to be like this to solve my problem. Thanks Paul string v = xr.ReadElementContentAsString(); var nf = Workbook.Styles.CellXfs[styleID].NumberFormatId; if ((nf >= 14 && nf <= 22) || (nf >= 45 && nf <= 47)) { double res; if (double.TryParse(v, NumberStyles.Any, CultureInfo.InvariantCulture, out res)) { if (Workbook.Date1904) { res += ExcelWorkbook.date1904Offset; } if (res >= -657435.0 && res < 2958465.9999999) { _values.SetValue(row, col, DateTime.FromOADate(res)); } else { //_values.SetValue(row, col, ""); // modified by Paul _values.SetValue(row, col, res); } } else { //_values.SetValue(row, col, ""); // modified by Paul _values.SetValue(row, col, v); } } else { double d; if (double.TryParse(v, NumberStyles.Any, CultureInfo.InvariantCulture, out d)) { _values.SetValue(row, col, d); } else { //_values.SetValue(row, col, double.NaN); // modified by Paul _values.SetValue(row, col, v); } }

Viewing all articles
Browse latest Browse all 2262

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>