a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.
5.73k
stars
1.43k
forks
source link
POI Bug-61281: ExportToXML(Stream,String,bool)@XSSFExportToXml can have export issues: #1228
Closed
tohidemyname closed 10 months ago
NPOI Version
master
The code is as follows:
public void ExportToXML(Stream os, String encoding, bool validate) {...
.... for (int j = startColumnIndex; j <= table.EndCellReference.Col; j++) { XSSFCell cell = (XSSFCell)row.GetCell(j); if (cell != null) { XSSFXmlColumnPr pointer = tableColumns[j - startColumnIndex]; String localXPath = pointer.LocalXPath; XmlNode currentNode = GetNodeByXPath(localXPath, tableRootNode, doc, false); ST_XmlDataType dataType = pointer.GetXmlDataType();
...}
POI fixed a bug:
https://github.com/apache/poi/commit/012ab1a9ad447fe17dd4a856a9c889c8a8fecb5e
The buggy code is quite similar: public void exportToXML(OutputStream os, String encoding, boolean validate) thro .{..
List tableColumns = table.getXmlColumnPrs();
...
for(int j = startColumnIndex; j<= table.getEndCellReference().getCol(); j++) {
int tableColumnIndex = j - startColumnIndex;
if (tableColumnIndex < tableColumns.size()) {
XSSFCell cell = row.getCell(j);
if (cell != null) {
XSSFXmlColumnPr pointer = tableColumns.get(tableColumnIndex);
String localXPath = pointer.getLocalXPath();
Node currentNode = getNodeByXPath(localXPath,tableRootNode,doc,false);
...}}
The fixed code is as follows:
public void exportToXML(OutputStream os, String encoding, boolean validate) thro .{.. List tableColumns = table.getCTTable().getTableColumns().getTableColumnList();
...
for (int j = startColumnIndex; j <= table.getEndCellReference().getCol(); j++) {
XSSFCell cell = row.getCell(j);
if (cell != null) {
int tableColumnIndex = j - startColumnIndex;
if (tableColumnIndex < tableColumns.size()) {
CTTableColumn ctTableColumn = tableColumns.get(tableColumnIndex);
if (ctTableColumn.getXmlColumnPr() != null) {
XSSFXmlColumnPr pointer = new XSSFXmlColumnPr(table, ctTableColumn,
ctTableColumn.getXmlColumnPr());
String localXPath = pointer.getLocalXPath();
Node currentNode = getNodeByXPath(localXPath,tableRootNode,doc,false);
mapCellOnNode(cell,currentNode);
}
...
}}