[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
This commit is contained in:
parent
748e0c4981
commit
eddad11775
@ -53,6 +53,7 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|||||||
import org.apache.poi.xssf.usermodel.XSSFTable;
|
import org.apache.poi.xssf.usermodel.XSSFTable;
|
||||||
import org.apache.poi.xssf.usermodel.helpers.XSSFSingleXmlCell;
|
import org.apache.poi.xssf.usermodel.helpers.XSSFSingleXmlCell;
|
||||||
import org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr;
|
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.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.NamedNodeMap;
|
import org.w3c.dom.NamedNodeMap;
|
||||||
@ -172,7 +173,7 @@ public class XSSFExportToXml implements Comparator<String>{
|
|||||||
// Exports elements and attributes mapped with tables
|
// Exports elements and attributes mapped with tables
|
||||||
if (table!=null) {
|
if (table!=null) {
|
||||||
|
|
||||||
List<XSSFXmlColumnPr> tableColumns = table.getXmlColumnPrs();
|
List<CTTableColumn> tableColumns = table.getCTTable().getTableColumns().getTableColumnList();
|
||||||
|
|
||||||
XSSFSheet sheet = table.getXSSFSheet();
|
XSSFSheet sheet = table.getXSSFSheet();
|
||||||
|
|
||||||
@ -188,16 +189,19 @@ public class XSSFExportToXml implements Comparator<String>{
|
|||||||
Node tableRootNode = getNodeByXPath(table.getCommonXpath(),doc.getFirstChild(),doc,true);
|
Node tableRootNode = getNodeByXPath(table.getCommonXpath(),doc.getFirstChild(),doc,true);
|
||||||
|
|
||||||
short startColumnIndex = table.getStartCellReference().getCol();
|
short startColumnIndex = table.getStartCellReference().getCol();
|
||||||
for(int j = startColumnIndex; j<= table.getEndCellReference().getCol(); j++) {
|
for (int j = startColumnIndex; j <= table.getEndCellReference().getCol(); j++) {
|
||||||
int tableColumnIndex = j - startColumnIndex;
|
XSSFCell cell = row.getCell(j);
|
||||||
if (tableColumnIndex < tableColumns.size()) {
|
if (cell != null) {
|
||||||
XSSFCell cell = row.getCell(j);
|
int tableColumnIndex = j - startColumnIndex;
|
||||||
if (cell != null) {
|
if (tableColumnIndex < tableColumns.size()) {
|
||||||
XSSFXmlColumnPr pointer = tableColumns.get(tableColumnIndex);
|
CTTableColumn ctTableColumn = tableColumns.get(tableColumnIndex);
|
||||||
String localXPath = pointer.getLocalXPath();
|
if (ctTableColumn.getXmlColumnPr() != null) {
|
||||||
Node currentNode = getNodeByXPath(localXPath,tableRootNode,doc,false);
|
XSSFXmlColumnPr pointer = new XSSFXmlColumnPr(table, ctTableColumn,
|
||||||
|
ctTableColumn.getXmlColumnPr());
|
||||||
mapCellOnNode(cell,currentNode);
|
String localXPath = pointer.getLocalXPath();
|
||||||
|
Node currentNode = getNodeByXPath(localXPath,tableRootNode,doc,false);
|
||||||
|
mapCellOnNode(cell,currentNode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -666,6 +666,8 @@ public final class TestXSSFExportToXML {
|
|||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
exporter.exportToXML(bos, true);
|
exporter.exportToXML(bos, true);
|
||||||
assertNotNull(DocumentHelper.readDocument(new ByteArrayInputStream(bos.toByteArray())));
|
assertNotNull(DocumentHelper.readDocument(new ByteArrayInputStream(bos.toByteArray())));
|
||||||
|
String exportedXml = bos.toString("UTF-8");
|
||||||
|
assertEquals("<Test><Test>1</Test></Test>", exportedXml.replaceAll("\\s+", ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user