diff options
author | PJ Fanning <fanningpj@apache.org> | 2017-07-12 10:46:13 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2017-07-12 10:46:13 +0000 |
commit | 012ab1a9ad447fe17dd4a856a9c889c8a8fecb5e (patch) | |
tree | cfa4111018cd0aaab498bde554c6f239c2cc9b62 /src/ooxml | |
parent | 2a42bbafc6c57a2b7fe7da5cd420fd7cdcb2be95 (diff) | |
download | poi-012ab1a9ad447fe17dd4a856a9c889c8a8fecb5e.tar.gz poi-012ab1a9ad447fe17dd4a856a9c889c8a8fecb5e.zip |
[Bug-61281] fix issue with export of table columns - Thanks to Daniel for the patch
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1801721 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml')
-rw-r--r-- | src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java | 26 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java | 2 |
2 files changed, 17 insertions, 11 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java index 0ed44d3048..814f0a04e1 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java @@ -53,6 +53,7 @@ import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFTable; import org.apache.poi.xssf.usermodel.helpers.XSSFSingleXmlCell; import org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; @@ -172,7 +173,7 @@ public class XSSFExportToXml implements Comparator<String>{ // Exports elements and attributes mapped with tables if (table!=null) { - List<XSSFXmlColumnPr> tableColumns = table.getXmlColumnPrs(); + List<CTTableColumn> tableColumns = table.getCTTable().getTableColumns().getTableColumnList(); XSSFSheet sheet = table.getXSSFSheet(); @@ -188,16 +189,19 @@ public class XSSFExportToXml implements Comparator<String>{ Node tableRootNode = getNodeByXPath(table.getCommonXpath(),doc.getFirstChild(),doc,true); short startColumnIndex = table.getStartCellReference().getCol(); - 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); - - mapCellOnNode(cell,currentNode); + 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); + } } } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java index 5c92901079..61d8a1b7f8 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java @@ -666,6 +666,8 @@ public final class TestXSSFExportToXML { ByteArrayOutputStream bos = new ByteArrayOutputStream(); exporter.exportToXML(bos, true); assertNotNull(DocumentHelper.readDocument(new ByteArrayInputStream(bos.toByteArray()))); + String exportedXml = bos.toString("UTF-8"); + assertEquals("<Test><Test>1</Test></Test>", exportedXml.replaceAll("\\s+", "")); } } } |