You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2017/07/12 10:46:14 UTC

svn commit: r1801721 - in /poi/trunk/src/ooxml: java/org/apache/poi/xssf/extractor/XSSFExportToXml.java testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java

Author: fanningpj
Date: Wed Jul 12 10:46:13 2017
New Revision: 1801721

URL: http://svn.apache.org/viewvc?rev=1801721&view=rev
Log:
[Bug-61281] fix issue with export of table columns - Thanks to Daniel for the patch

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java?rev=1801721&r1=1801720&r2=1801721&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java Wed Jul 12 10:46:13 2017
@@ -53,6 +53,7 @@ import org.apache.poi.xssf.usermodel.XSS
 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
                 // 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
                         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);
+                                    }
                                 }
                             }
                         }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java?rev=1801721&r1=1801720&r2=1801721&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java Wed Jul 12 10:46:13 2017
@@ -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+", ""));
         }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org