Search in sources :

Example 21 with POIXMLDocumentPart

use of org.apache.poi.POIXMLDocumentPart in project poi by apache.

the class TestXSSFExportToXML method testXmlExportIgnoresEmptyCells_Bugzilla_55924.

public void testXmlExportIgnoresEmptyCells_Bugzilla_55924() throws Exception {
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("55924.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 euro = a.split("<EUR>")[1].split("</EUR>")[0].trim();
        assertEquals("1", euro);
        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 22 with POIXMLDocumentPart

use of org.apache.poi.POIXMLDocumentPart in project poi by apache.

the class TestXSSFExportToXML method testFormulaCells_Bugzilla_55927.

public void testFormulaCells_Bugzilla_55927() throws Exception {
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("55927.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("2012-01-13", xmlData.split("<DATE>")[1].split("</DATE>")[0].trim());
        assertEquals("2012-02-16", xmlData.split("<FORMULA_DATE>")[1].split("</FORMULA_DATE>")[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 23 with POIXMLDocumentPart

use of org.apache.poi.POIXMLDocumentPart in project poi by apache.

the class TestXSSFExportToXML method testExportToXML.

public void testExportToXML() throws Exception {
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMappings.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("ro", docente);
        assertEquals("ro", nome);
        assertEquals("ds", tutor);
        assertEquals("gs", cdl);
        assertEquals("g", durata);
        assertEquals("gvvv", argomento);
        assertEquals("aaaa", progetto);
        assertEquals("aa", 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 24 with POIXMLDocumentPart

use of org.apache.poi.POIXMLDocumentPart 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);
}
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 25 with POIXMLDocumentPart

use of org.apache.poi.POIXMLDocumentPart in project poi by apache.

the class TestXSSFBugs method bug51470.

@Test
public void bug51470() throws IOException {
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("51470.xlsx");
    XSSFSheet sh0 = wb.getSheetAt(0);
    XSSFSheet sh1 = wb.cloneSheet(0);
    List<RelationPart> rels0 = sh0.getRelationParts();
    List<RelationPart> rels1 = sh1.getRelationParts();
    assertEquals(1, rels0.size());
    assertEquals(1, rels1.size());
    PackageRelationship pr0 = rels0.get(0).getRelationship();
    PackageRelationship pr1 = rels1.get(0).getRelationship();
    assertEquals(pr0.getTargetMode(), pr1.getTargetMode());
    assertEquals(pr0.getTargetURI(), pr1.getTargetURI());
    POIXMLDocumentPart doc0 = rels0.get(0).getDocumentPart();
    POIXMLDocumentPart doc1 = rels1.get(0).getDocumentPart();
    assertEquals(doc0, doc1);
    wb.close();
}
Also used : RelationPart(org.apache.poi.POIXMLDocumentPart.RelationPart) PackageRelationship(org.apache.poi.openxml4j.opc.PackageRelationship) POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Test(org.junit.Test)

Aggregations

POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)42 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)16 MapInfo (org.apache.poi.xssf.model.MapInfo)14 XSSFMap (org.apache.poi.xssf.usermodel.XSSFMap)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 POIXMLException (org.apache.poi.POIXMLException)9 XmlException (org.apache.xmlbeans.XmlException)7 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)3 HashMap (java.util.HashMap)3 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)2 PackageRelationship (org.apache.poi.openxml4j.opc.PackageRelationship)2 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)2 CellReference (org.apache.poi.ss.util.CellReference)2 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)2 CTAxDataSource (org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource)2 CTChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTChart)2