use of org.apache.poi.xssf.model.MapInfo in project poi by apache.
the class TestXSSFExportToXML method testXPathOrdering.
public void testXPathOrdering() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXmlMappings-inverse-order.xlsx");
boolean found = false;
for (POIXMLDocumentPart p : wb.getRelations()) {
if (p instanceof MapInfo) {
MapInfo mapInfo = (MapInfo) p;
XSSFMap map = mapInfo.getXSSFMapById(1);
XSSFExportToXml exporter = new XSSFExportToXml(map);
assertEquals(1, exporter.compare("/CORSO/DOCENTE", "/CORSO/NOME"));
assertEquals(-1, exporter.compare("/CORSO/NOME", "/CORSO/DOCENTE"));
}
found = true;
}
assertTrue(found);
}
use of org.apache.poi.xssf.model.MapInfo in project poi by apache.
the class TestXSSFExportToXML method testExportDataTypes.
public void testExportDataTypes() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("55923.xlsx");
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(0);
Cell cString = row.createCell(0);
cString.setCellValue("somestring");
cString.setCellType(CellType.STRING);
Cell cBoolean = row.createCell(1);
cBoolean.setCellValue(true);
cBoolean.setCellType(CellType.BOOLEAN);
Cell cError = row.createCell(2);
cError.setCellType(CellType.ERROR);
Cell cFormulaString = row.createCell(3);
cFormulaString.setCellFormula("A1");
cFormulaString.setCellType(CellType.FORMULA);
Cell cFormulaNumeric = row.createCell(4);
cFormulaNumeric.setCellFormula("F1");
cFormulaNumeric.setCellType(CellType.FORMULA);
Cell cNumeric = row.createCell(5);
cNumeric.setCellValue(1.2);
cNumeric.setCellType(CellType.NUMERIC);
Cell cDate = row.createCell(6);
cDate.setCellValue(new Date());
cDate.setCellType(CellType.NUMERIC);
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);
ByteArrayOutputStream os = new ByteArrayOutputStream();
exporter.exportToXML(os, true);
String xmlData = os.toString("UTF-8");
assertNotNull(xmlData);
assertFalse(xmlData.equals(""));
parseXML(xmlData);
found = true;
}
assertTrue(found);
}
use of org.apache.poi.xssf.model.MapInfo in project poi by apache.
the class TestXSSFExportToXML method test55850ComplexXmlExport.
public void test55850ComplexXmlExport() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("55850.xlsx");
boolean found = false;
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);
assertFalse(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);
parseXML(xmlData);
found = true;
}
assertTrue(found);
}
use of org.apache.poi.xssf.model.MapInfo in project poi by apache.
the class TestXSSFExportToXML method testValidateFalse.
public void testValidateFalse() 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);
ByteArrayOutputStream os = new ByteArrayOutputStream();
exporter.exportToXML(os, false);
String xmlData = os.toString("UTF-8");
assertNotNull(xmlData);
assertFalse(xmlData.equals(""));
parseXML(xmlData);
found = true;
}
assertTrue(found);
}
Aggregations