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

Edited Unassigned: Exception with Empty Elements [15607]

$
0
0
Some XLSX files (especially those generated from SSRS) have a lot of formatting and whitespace, which causes either an exception (_Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it._) or causes Excel to repair the file before opening.

The reason for this is that some <t> elements have whitespace that is removed automatically in the XmlReader.ReadOuterXml() method, and empty <t> elements are causing these downstream issues. The source of the issue occurs here (line 1366 ExcelWorksheet.cs):
```
var rXml = xr.ReadOuterXml();
while (xr.LocalName == "r")
{
rXml += xr.ReadOuterXml();
}
SetValueInner(address._fromRow, address._fromCol, rXml);
```

I am not familiar enough with the OpenOfficeXml format to implement a generalized solution for other places where this may be an issue, but a fix for this particular problem could be:
```
var rXml = xr.ReadOuterXml();
while (xr.LocalName == "r")
{
rXml += xr.ReadOuterXml();
}
rXml = Regex.Replace(rXml, "<t(?<attr>[^>]+)?></t>", "<t${attr}> </t>");
SetValueInner(address._fromRow, address._fromCol, rXml);
```

Viewing all articles
Browse latest Browse all 2262

Trending Articles



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