Bug 55850: fix NullPointerException during extraction from XSSF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1549007 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
18f9a3e88e
commit
2a08a1dd10
@ -41,11 +41,11 @@ import javax.xml.validation.SchemaFactory;
|
|||||||
import javax.xml.validation.Validator;
|
import javax.xml.validation.Validator;
|
||||||
|
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFTable;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFCell;
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFMap;
|
import org.apache.poi.xssf.usermodel.XSSFMap;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
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.XSSFSingleXmlCell;
|
||||||
import org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr;
|
import org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXmlDataType;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXmlDataType;
|
||||||
@ -476,7 +476,7 @@ public class XSSFExportToXml implements Comparator<String>{
|
|||||||
if (!"".equals(complexTypeName)) {
|
if (!"".equals(complexTypeName)) {
|
||||||
NodeList complexTypeList = xmlSchema.getChildNodes();
|
NodeList complexTypeList = xmlSchema.getChildNodes();
|
||||||
for(int i=0; i< complexTypeList.getLength();i++) {
|
for(int i=0; i< complexTypeList.getLength();i++) {
|
||||||
Node node = list.item(i);
|
Node node = complexTypeList.item(i);
|
||||||
if ( node instanceof Element) {
|
if ( node instanceof Element) {
|
||||||
if (node.getLocalName().equals("complexType")) {
|
if (node.getLocalName().equals("complexType")) {
|
||||||
Node nameAttribute = node.getAttributes().getNamedItem("name");
|
Node nameAttribute = node.getAttributes().getNamedItem("name");
|
||||||
@ -504,4 +504,4 @@ public class XSSFExportToXml implements Comparator<String>{
|
|||||||
}
|
}
|
||||||
return complexTypeNode;
|
return complexTypeNode;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -176,4 +176,42 @@ public final class TestXSSFExportToXML extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void test55850ComplexXmlExport() throws Exception {
|
||||||
|
|
||||||
|
XSSFWorkbook wb = XSSFTestDataSamples
|
||||||
|
.openSampleWorkbook("55850.xlsx");
|
||||||
|
|
||||||
|
for (POIXMLDocumentPart p : wb.getRelations()) {
|
||||||
|
|
||||||
|
if (!(p instanceof MapInfo)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
MapInfo mapInfo = (MapInfo) p;
|
||||||
|
|
||||||
|
XSSFMap map = mapInfo.getXSSFMapById(2);
|
||||||
|
|
||||||
|
assertNotNull("XSSFMap is null", map);
|
||||||
|
|
||||||
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
|
exporter.exportToXML(os, true);
|
||||||
|
String xmlData = os.toString("UTF-8");
|
||||||
|
|
||||||
|
assertNotNull(xmlData);
|
||||||
|
assertTrue(!xmlData.equals(""));
|
||||||
|
|
||||||
|
String a = xmlData.split("<A>")[1].split("</A>")[0].trim();
|
||||||
|
String b = a.split("<B>")[1].split("</B>")[0].trim();
|
||||||
|
String c = b.split("<C>")[1].split("</C>")[0].trim();
|
||||||
|
String d = c.split("<D>")[1].split("</Dd>")[0].trim();
|
||||||
|
String e = d.split("<E>")[1].split("</EA>")[0].trim();
|
||||||
|
|
||||||
|
String euro = e.split("<EUR>")[1].split("</EUR>")[0].trim();
|
||||||
|
String chf = e.split("<CHF>")[1].split("</CHF>")[0].trim();
|
||||||
|
|
||||||
|
assertEquals("15", euro);
|
||||||
|
assertEquals("19", chf);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
BIN
test-data/spreadsheet/55850.xlsx
Normal file
BIN
test-data/spreadsheet/55850.xlsx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user