use of org.apache.poi.xssf.usermodel.XSSFMap in project poi by apache.
the class TestXSSFExportToXML method testFormulaCells_Bugzilla_55926.
public void testFormulaCells_Bugzilla_55926() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("55926.xlsx");
boolean found = false;
for (POIXMLDocumentPart p : wb.getRelations()) {
if (!(p instanceof MapInfo)) {
continue;
}
MapInfo mapInfo = (MapInfo) p;
XSSFMap map = mapInfo.getXSSFMapById(1);
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);
assertFalse(xmlData.equals(""));
String a = xmlData.split("<A>")[1].split("</A>")[0].trim();
String doubleValue = a.split("<DOUBLE>")[1].split("</DOUBLE>")[0].trim();
String stringValue = a.split("<STRING>")[1].split("</STRING>")[0].trim();
assertEquals("Hello World", stringValue);
assertEquals("5.1", doubleValue);
parseXML(xmlData);
found = true;
}
assertTrue(found);
}
use of org.apache.poi.xssf.usermodel.XSSFMap in project poi by apache.
the class XSSFFileHandler method exportToXML.
private void exportToXML(XSSFWorkbook wb) throws SAXException, ParserConfigurationException, TransformerException {
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
ByteArrayOutputStream os = new ByteArrayOutputStream();
exporter.exportToXML(os, true);
}
}
use of org.apache.poi.xssf.usermodel.XSSFMap in project poi by apache.
the class TestXSSFExportToXML method testXmlExportCompare_Bug_55923.
public void testXmlExportCompare_Bug_55923() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("55923.xlsx");
boolean found = false;
for (POIXMLDocumentPart p : wb.getRelations()) {
if (!(p instanceof MapInfo)) {
continue;
}
MapInfo mapInfo = (MapInfo) p;
XSSFMap map = mapInfo.getXSSFMapById(4);
assertNotNull("XSSFMap is null", map);
XSSFExportToXml exporter = new XSSFExportToXml(map);
assertEquals(0, exporter.compare("", ""));
assertEquals(0, exporter.compare("/", "/"));
assertEquals(0, exporter.compare("//", "//"));
assertEquals(0, exporter.compare("/a/", "/b/"));
assertEquals(-1, exporter.compare("/ns1:Entry/ns1:A/ns1:B/ns1:C/ns1:E/ns1:EUR", "/ns1:Entry/ns1:A/ns1:B/ns1:C/ns1:E/ns1:CHF"));
found = true;
}
assertTrue(found);
}
use of org.apache.poi.xssf.usermodel.XSSFMap in project poi by apache.
the class TestXSSFImportFromXML method testMultiTable.
@Test(timeout = 60000)
public void testMultiTable() throws IOException, XPathExpressionException, SAXException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMappings-complex-type.xlsx");
try {
String cellC6 = "c6";
String cellC7 = "c7";
String cellC8 = "c8";
String cellC9 = "c9";
String testXML = "<ns1:MapInfo xmlns:ns1=\"" + NS_SPREADSHEETML + "\" SelectionNamespaces=\"\">" + "<ns1:Schema ID=\"" + cellC6 + "\" SchemaRef=\"a\" />" + "<ns1:Schema ID=\"" + cellC7 + "\" SchemaRef=\"b\" />" + "<ns1:Schema ID=\"" + cellC8 + "\" SchemaRef=\"c\" />" + "<ns1:Schema ID=\"" + cellC9 + "\" SchemaRef=\"d\" />";
for (int i = 10; i < 10010; i++) {
testXML += "<ns1:Schema ID=\"c" + i + "\" SchemaRef=\"d\" />";
}
testXML += "<ns1:Map ID=\"1\" Name=\"\" RootElement=\"\" SchemaID=\"\" ShowImportExportValidationErrors=\"\" AutoFit=\"\" Append=\"\" PreserveSortAFLayout=\"\" PreserveFormat=\"\">" + "<ns1:DataBinding DataBindingLoadMode=\"\" />" + "</ns1:Map>" + "<ns1:Map ID=\"2\" Name=\"\" RootElement=\"\" SchemaID=\"\" ShowImportExportValidationErrors=\"\" AutoFit=\"\" Append=\"\" PreserveSortAFLayout=\"\" PreserveFormat=\"\">" + "<ns1:DataBinding DataBindingLoadMode=\"\" />" + "</ns1:Map>" + "<ns1:Map ID=\"3\" Name=\"\" RootElement=\"\" SchemaID=\"\" ShowImportExportValidationErrors=\"\" AutoFit=\"\" Append=\"\" PreserveSortAFLayout=\"\" PreserveFormat=\"\">" + "<ns1:DataBinding DataBindingLoadMode=\"\" />" + "</ns1:Map>" + "</ns1:MapInfo>