Search in sources :

Example 11 with MapInfo

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);
}
Also used : POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) XSSFMap(org.apache.poi.xssf.usermodel.XSSFMap) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) MapInfo(org.apache.poi.xssf.model.MapInfo)

Example 12 with MapInfo

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);
}
Also used : POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) XSSFMap(org.apache.poi.xssf.usermodel.XSSFMap) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) MapInfo(org.apache.poi.xssf.model.MapInfo) Row(org.apache.poi.ss.usermodel.Row) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) Date(java.util.Date)

Example 13 with MapInfo

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);
}
Also used : POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) XSSFMap(org.apache.poi.xssf.usermodel.XSSFMap) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) MapInfo(org.apache.poi.xssf.model.MapInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 14 with MapInfo

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);
}
Also used : POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) XSSFMap(org.apache.poi.xssf.usermodel.XSSFMap) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) MapInfo(org.apache.poi.xssf.model.MapInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)14 MapInfo (org.apache.poi.xssf.model.MapInfo)14 XSSFMap (org.apache.poi.xssf.usermodel.XSSFMap)13 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ArrayListValuedHashMap (org.apache.commons.collections4.multimap.ArrayListValuedHashMap)1 POIXMLException (org.apache.poi.POIXMLException)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Row (org.apache.poi.ss.usermodel.Row)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1 CalculationChain (org.apache.poi.xssf.model.CalculationChain)1 ExternalLinksTable (org.apache.poi.xssf.model.ExternalLinksTable)1 SharedStringsTable (org.apache.poi.xssf.model.SharedStringsTable)1 StylesTable (org.apache.poi.xssf.model.StylesTable)1 ThemesTable (org.apache.poi.xssf.model.ThemesTable)1 XmlException (org.apache.xmlbeans.XmlException)1