use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class XSSFTestDataSamples method readBack.
/**
* Read back a workbook that was written out to a memory buffer with
* {@link #writeOut(Workbook)} or {@link #writeOutAndClose(Workbook)}.
*
* @param file the workbook file to read
* @return the read back workbook
* @throws IOException
*/
public static XSSFWorkbook readBack(ByteArrayOutputStream out) throws IOException {
InputStream is = new ByteArrayInputStream(out.toByteArray());
out.close();
try {
return new XSSFWorkbook(is);
} finally {
is.close();
}
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class TestReadOnlySharedStringsTable method testEmptySSTOnPackageObtainedViaWorkbook.
public void testEmptySSTOnPackageObtainedViaWorkbook() throws Exception {
XSSFWorkbook wb = new XSSFWorkbook(_ssTests.openResourceAsStream("noSharedStringTable.xlsx"));
OPCPackage pkg = wb.getPackage();
assertEmptySST(pkg);
wb.close();
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class TestXSSFExportToXML method testXmlExportSchemaOrderingBug_Bugzilla_55923.
public void testXmlExportSchemaOrderingBug_Bugzilla_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);
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 a_b = a.split("<B>")[1].split("</B>")[0].trim();
String a_b_c = a_b.split("<C>")[1].split("</C>")[0].trim();
String a_b_c_e = a_b_c.split("<E>")[1].split("</EA>")[0].trim();
String a_b_c_e_euro = a_b_c_e.split("<EUR>")[1].split("</EUR>")[0].trim();
String a_b_c_e_chf = a_b_c_e.split("<CHF>")[1].split("</CHF>")[0].trim();
assertEquals("1", a_b_c_e_euro);
assertEquals("2", a_b_c_e_chf);
String a_b_d = a_b.split("<D>")[1].split("</Dd>")[0].trim();
String a_b_d_e = a_b_d.split("<E>")[1].split("</EA>")[0].trim();
String a_b_d_e_euro = a_b_d_e.split("<EUR>")[1].split("</EUR>")[0].trim();
String a_b_d_e_chf = a_b_d_e.split("<CHF>")[1].split("</CHF>")[0].trim();
assertEquals("3", a_b_d_e_euro);
assertEquals("4", a_b_d_e_chf);
found = true;
}
assertTrue(found);
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class TestXSSFExportToXML method testXmlExportSchemaWithXSAllTag_Bugzilla_56169.
public void testXmlExportSchemaWithXSAllTag_Bugzilla_56169() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56169.xlsx");
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
ByteArrayOutputStream os = new ByteArrayOutputStream();
exporter.exportToXML(os, true);
String xmlData = os.toString("UTF-8");
assertNotNull(xmlData);
assertTrue(!xmlData.equals(""));
String a = xmlData.split("<A>")[1].split("</A>")[0].trim();
String a_b = a.split("<B>")[1].split("</B>")[0].trim();
String a_b_c = a_b.split("<C>")[1].split("</C>")[0].trim();
String a_b_c_e = a_b_c.split("<E>")[1].split("</EA>")[0].trim();
String a_b_c_e_euro = a_b_c_e.split("<EUR>")[1].split("</EUR>")[0].trim();
String a_b_c_e_chf = a_b_c_e.split("<CHF>")[1].split("</CHF>")[0].trim();
assertEquals("1", a_b_c_e_euro);
assertEquals("2", a_b_c_e_chf);
String a_b_d = a_b.split("<D>")[1].split("</Dd>")[0].trim();
String a_b_d_e = a_b_d.split("<E>")[1].split("</EA>")[0].trim();
String a_b_d_e_euro = a_b_d_e.split("<EUR>")[1].split("</EUR>")[0].trim();
String a_b_d_e_chf = a_b_d_e.split("<CHF>")[1].split("</CHF>")[0].trim();
assertEquals("3", a_b_d_e_euro);
assertEquals("4", a_b_d_e_chf);
}
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook 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);
}
Aggregations