Search in sources :

Example 16 with XSSFMap

use of org.apache.poi.xssf.usermodel.XSSFMap in project poi by apache.

the class MapInfo method readFrom.

public void readFrom(InputStream is) throws IOException {
    try {
        MapInfoDocument doc = MapInfoDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
        mapInfo = doc.getMapInfo();
        maps = new HashMap<Integer, XSSFMap>();
        for (CTMap map : mapInfo.getMapArray()) {
            maps.put((int) map.getID(), new XSSFMap(map, this));
        }
    } catch (XmlException e) {
        throw new IOException(e.getLocalizedMessage());
    }
}
Also used : XmlException(org.apache.xmlbeans.XmlException) XSSFMap(org.apache.poi.xssf.usermodel.XSSFMap) MapInfoDocument(org.openxmlformats.schemas.spreadsheetml.x2006.main.MapInfoDocument) IOException(java.io.IOException) CTMap(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMap)

Example 17 with XSSFMap

use of org.apache.poi.xssf.usermodel.XSSFMap in project poi by apache.

the class TestXSSFExportToXML method testRefElementsInXmlSchema_Bugzilla_56730.

public void testRefElementsInXmlSchema_Bugzilla_56730() throws Exception {
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56730.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(""));
        assertEquals("2014-12-31", xmlData.split("<DATE>")[1].split("</DATE>")[0].trim());
        assertEquals("12.5", xmlData.split("<REFELEMENT>")[1].split("</REFELEMENT>")[0].trim());
        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 18 with XSSFMap

use of org.apache.poi.xssf.usermodel.XSSFMap in project poi by apache.

the class TestXSSFExportToXML method testMultiTable.

public void testMultiTable() throws Exception {
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMappings-complex-type.xlsx");
    boolean found = false;
    for (POIXMLDocumentPart p : wb.getRelations()) {
        if (p instanceof MapInfo) {
            MapInfo mapInfo = (MapInfo) p;
            XSSFMap map = mapInfo.getXSSFMapById(2);
            assertNotNull(map);
            XSSFExportToXml exporter = new XSSFExportToXml(map);
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            exporter.exportToXML(os, true);
            String xml = os.toString("UTF-8");
            assertNotNull(xml);
            String[] regexConditions = { "<MapInfo", "</MapInfo>", "<Schema ID=\"1\" Namespace=\"\" SchemaRef=\"\"/>", "<Schema ID=\"4\" Namespace=\"\" SchemaRef=\"\"/>", "DataBinding", "Map Append=\"false\" AutoFit=\"false\" ID=\"1\"", "Map Append=\"false\" AutoFit=\"false\" ID=\"5\"" };
            for (String condition : regexConditions) {
                Pattern pattern = Pattern.compile(condition);
                Matcher matcher = pattern.matcher(xml);
                assertTrue(matcher.find());
            }
        }
        found = true;
    }
    assertTrue(found);
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) 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 19 with XSSFMap

use of org.apache.poi.xssf.usermodel.XSSFMap in project poi by apache.

the class TestXSSFExportToXML method testExportToXMLInverseOrder.

public void testExportToXMLInverseOrder() throws Exception {
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXmlMappings-inverse-order.xlsx");
    boolean found = false;
    for (POIXMLDocumentPart p : wb.getRelations()) {
        if (!(p instanceof MapInfo)) {
            continue;
        }
        MapInfo mapInfo = (MapInfo) p;
        XSSFMap map = mapInfo.getXSSFMapById(1);
        XSSFExportToXml exporter = new XSSFExportToXml(map);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        exporter.exportToXML(os, true);
        String xml = os.toString("UTF-8");
        assertNotNull(xml);
        assertFalse(xml.equals(""));
        String docente = xml.split("<DOCENTE>")[1].split("</DOCENTE>")[0].trim();
        String nome = xml.split("<NOME>")[1].split("</NOME>")[0].trim();
        String tutor = xml.split("<TUTOR>")[1].split("</TUTOR>")[0].trim();
        String cdl = xml.split("<CDL>")[1].split("</CDL>")[0].trim();
        String durata = xml.split("<DURATA>")[1].split("</DURATA>")[0].trim();
        String argomento = xml.split("<ARGOMENTO>")[1].split("</ARGOMENTO>")[0].trim();
        String progetto = xml.split("<PROGETTO>")[1].split("</PROGETTO>")[0].trim();
        String crediti = xml.split("<CREDITI>")[1].split("</CREDITI>")[0].trim();
        assertEquals("aa", nome);
        assertEquals("aaaa", docente);
        assertEquals("gvvv", tutor);
        assertEquals("g", cdl);
        assertEquals("gs", durata);
        assertEquals("ds", argomento);
        assertEquals("ro", progetto);
        assertEquals("ro", crediti);
        parseXML(xml);
        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 20 with XSSFMap

use of org.apache.poi.xssf.usermodel.XSSFMap 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)

Aggregations

XSSFMap (org.apache.poi.xssf.usermodel.XSSFMap)24 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)22 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)14 MapInfo (org.apache.poi.xssf.model.MapInfo)13 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)6 Test (org.junit.Test)5 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)3 Date (java.util.Date)2 XSSFExportToXml (org.apache.poi.xssf.extractor.XSSFExportToXml)2 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)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 XmlException (org.apache.xmlbeans.XmlException)1 CTMap (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMap)1