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

Edited Unassigned: When Excel workbook contains an invalid date, EPPlus raises the Exception invalid OleAut date. [14898]

$
0
0
Hello,

When i try to open a excel file which contains a cell containing an invalid date, Excel displays it with ####### into the cell and 3778816,1688361 into the edit bar. But when I try to open the file with EPPlus, it raises an exception invalid OleAut date.

You will find an excel invalid file as attachments, and the following code can correct the issue. (it modifies the ExcelWorksheet class)

```
private object GetValueFromXml(ExcelCell cell, XmlTextReader xr)
{
object value;

//XmlNode vnode = colNode.SelectSingleNode("d:v", NameSpaceManager);
//if (vnode == null) return null;

if (cell.DataType == "s")
{
int ix = xr.ReadElementContentAsInt();
value = _package.Workbook._sharedStringsList[ix].Text;
cell.IsRichText = _package.Workbook._sharedStringsList[ix].isRichText;
}
else if (cell.DataType == "str")
{
value = xr.ReadElementContentAsString();
}
else if (cell.DataType == "b")
{
value = (xr.ReadElementContentAsString() != "0");
}
else
{
int n = cell.Style.Numberformat.NumFmtID;
string v = xr.ReadElementContentAsString();

if ((n >= 14 && n <= 22) || (n >= 45 && n <= 47))
{
double res;
if (double.TryParse(v, NumberStyles.Any, CultureInfo.InvariantCulture, out res))
{
if (res >= -657435.0 && res < 2958465)
value = DateTime.FromOADate(res);
else
value = "";
}
else
{
value = "";
}
}
else
{
double d;
if (double.TryParse(v, NumberStyles.Any, CultureInfo.InvariantCulture, out d))
{
value = d;
}
else
{
value = double.NaN;
}
}
}
return value;
}
```
Regards, and thanks for this excellent component !

Viewing all articles
Browse latest Browse all 2262

Trending Articles



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