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-unsubscr...@poi.apache.org
For additional commands, e-mail: commits-h...@poi.apache.org

Reply via email to