use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project poi by apache.
the class SXSSFITestDataProvider method openSampleWorkbook.
@Override
public Workbook openSampleWorkbook(String sampleFileName) {
XSSFWorkbook xssfWorkbook = XSSFITestDataProvider.instance.openSampleWorkbook(sampleFileName);
SXSSFWorkbook swb = new SXSSFWorkbook(xssfWorkbook);
instances.add(swb);
return swb;
}
use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project poi by apache.
the class TestXSSFBugs method saveAndReloadReport.
private void saveAndReloadReport(Workbook wb, File outFile) throws IOException {
// run some method on the font to verify if it is "disconnected" already
//for(short i = 0;i < 256;i++)
{
Font font = wb.getFontAt((short) 0);
if (font instanceof XSSFFont) {
XSSFFont xfont = (XSSFFont) wb.getFontAt((short) 0);
CTFontImpl ctFont = (CTFontImpl) xfont.getCTFont();
assertEquals(0, ctFont.sizeOfBArray());
}
}
FileOutputStream fileOutStream = new FileOutputStream(outFile);
try {
wb.write(fileOutStream);
} finally {
fileOutStream.close();
}
FileInputStream is = new FileInputStream(outFile);
try {
Workbook newWB = null;
try {
if (wb instanceof XSSFWorkbook) {
newWB = new XSSFWorkbook(is);
} else if (wb instanceof HSSFWorkbook) {
newWB = new HSSFWorkbook(is);
} else if (wb instanceof SXSSFWorkbook) {
newWB = new SXSSFWorkbook(new XSSFWorkbook(is));
} else {
throw new IllegalStateException("Unknown workbook: " + wb);
}
assertNotNull(newWB.getSheet("test"));
} finally {
if (newWB != null) {
newWB.close();
}
}
} finally {
is.close();
}
}
use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project poi by apache.
the class TestXSSFSheet method runGetTopRow.
private void runGetTopRow(String file, boolean isXSSF, int... topRows) throws IOException {
final Workbook wb = (isXSSF) ? XSSFTestDataSamples.openSampleWorkbook(file) : HSSFTestDataSamples.openSampleWorkbook(file);
for (int si = 0; si < wb.getNumberOfSheets(); si++) {
Sheet sh = wb.getSheetAt(si);
assertNotNull(sh.getSheetName());
assertEquals("Did not match for sheet " + si, topRows[si], sh.getTopRow());
}
// for XSSF also test with SXSSF
if (isXSSF) {
Workbook swb = new SXSSFWorkbook((XSSFWorkbook) wb);
for (int si = 0; si < swb.getNumberOfSheets(); si++) {
Sheet sh = swb.getSheetAt(si);
assertNotNull(sh.getSheetName());
assertEquals("Did not match for sheet " + si, topRows[si], sh.getTopRow());
}
swb.close();
}
wb.close();
}
use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project poi by apache.
the class TestXSSFTable method bug56274.
@Test
public void bug56274() throws IOException {
// read sample file
XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("56274.xlsx");
// read the original sheet header order
XSSFRow row = wb1.getSheetAt(0).getRow(0);
List<String> headers = new ArrayList<String>();
for (Cell cell : row) {
headers.add(cell.getStringCellValue());
}
// save the worksheet as-is using SXSSF
File outputFile = TempFile.createTempFile("poi-56274", ".xlsx");
SXSSFWorkbook outputWorkbook = new SXSSFWorkbook(wb1);
FileOutputStream fos = new FileOutputStream(outputFile);
outputWorkbook.write(fos);
fos.close();
outputWorkbook.close();
// re-read the saved file and make sure headers in the xml are in the original order
FileInputStream fis = new FileInputStream(outputFile);
XSSFWorkbook wb2 = new XSSFWorkbook(fis);
fis.close();
CTTable ctTable = wb2.getSheetAt(0).getTables().get(0).getCTTable();
CTTableColumn[] ctTableColumnArray = ctTable.getTableColumns().getTableColumnArray();
assertEquals("number of headers in xml table should match number of header cells in worksheet", headers.size(), ctTableColumnArray.length);
for (int i = 0; i < headers.size(); i++) {
assertEquals("header name in xml table should match number of header cells in worksheet", headers.get(i), ctTableColumnArray[i].getName());
}
assertTrue(outputFile.delete());
wb2.close();
wb1.close();
}
use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project poi by apache.
the class TestXSSFSheet method runGetLeftCol.
private void runGetLeftCol(String file, boolean isXSSF, int... topRows) throws IOException {
final Workbook wb = (isXSSF) ? XSSFTestDataSamples.openSampleWorkbook(file) : HSSFTestDataSamples.openSampleWorkbook(file);
for (int si = 0; si < wb.getNumberOfSheets(); si++) {
Sheet sh = wb.getSheetAt(si);
assertNotNull(sh.getSheetName());
assertEquals("Did not match for sheet " + si, topRows[si], sh.getLeftCol());
}
// for XSSF also test with SXSSF
if (isXSSF) {
Workbook swb = new SXSSFWorkbook((XSSFWorkbook) wb);
for (int si = 0; si < swb.getNumberOfSheets(); si++) {
Sheet sh = swb.getSheetAt(si);
assertNotNull(sh.getSheetName());
assertEquals("Did not match for sheet " + si, topRows[si], sh.getLeftCol());
}
swb.close();
}
wb.close();
}
Aggregations