use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestPackage method openZipBombFile.
private void openZipBombFile(String file) throws IOException, OpenXML4JException, XmlException {
try {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook(file);
wb.close();
POITextExtractor extractor = ExtractorFactory.createExtractor(HSSFTestDataSamples.getSampleFile("poc-shared-strings.xlsx"));
try {
assertNotNull(extractor);
extractor.getText();
} finally {
extractor.close();
}
fail("Should catch an exception because of a ZipBomb");
} catch (IllegalStateException e) {
if (!e.getMessage().contains("The text would exceed the max allowed overall size of extracted text.")) {
throw e;
}
} catch (POIXMLException e) {
checkForZipBombException(e);
}
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestSumifsXSSF method testBug60858.
/**
* handle null cell predicate
*/
@Test
public void testBug60858() {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("bug60858.xlsx");
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
Sheet sheet = wb.getSheetAt(0);
Cell cell = sheet.getRow(1).getCell(5);
fe.evaluate(cell);
assertEquals(0.0, cell.getNumericCellValue(), 0.0000000000000001);
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestSXSSFCell method testPreserveSpaces.
@Test
public void testPreserveSpaces() throws IOException {
String[] samplesWithSpaces = { " POI", "POI ", " POI ", "\nPOI", "\n\nPOI \n" };
for (String str : samplesWithSpaces) {
Workbook swb = _testDataProvider.createWorkbook();
Cell sCell = swb.createSheet().createRow(0).createCell(0);
sCell.setCellValue(str);
assertEquals(sCell.getStringCellValue(), str);
// read back as XSSF and check that xml:spaces="preserve" is set
XSSFWorkbook xwb = (XSSFWorkbook) _testDataProvider.writeOutAndReadBack(swb);
XSSFCell xCell = xwb.getSheetAt(0).getRow(0).getCell(0);
CTRst is = xCell.getCTCell().getIs();
XmlCursor c = is.newCursor();
c.toNextToken();
String t = c.getAttributeText(new QName("http://www.w3.org/XML/1998/namespace", "space"));
c.dispose();
assertEquals("expected xml:spaces=\"preserve\" \"" + str + "\"", "preserve", t);
xwb.close();
swb.close();
}
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestSXSSFBugs method bug49253.
/**
* Setting repeating rows and columns shouldn't break
* any print settings that were there before
*/
@Test
public void bug49253() throws Exception {
Workbook wb1 = new SXSSFWorkbook();
Workbook wb2 = new SXSSFWorkbook();
CellRangeAddress cra = CellRangeAddress.valueOf("C2:D3");
// No print settings before repeating
Sheet s1 = wb1.createSheet();
s1.setRepeatingColumns(cra);
s1.setRepeatingRows(cra);
PrintSetup ps1 = s1.getPrintSetup();
assertEquals(false, ps1.getValidSettings());
assertEquals(false, ps1.getLandscape());
// Had valid print settings before repeating
Sheet s2 = wb2.createSheet();
PrintSetup ps2 = s2.getPrintSetup();
ps2.setLandscape(false);
assertEquals(true, ps2.getValidSettings());
assertEquals(false, ps2.getLandscape());
s2.setRepeatingColumns(cra);
s2.setRepeatingRows(cra);
ps2 = s2.getPrintSetup();
assertEquals(true, ps2.getValidSettings());
assertEquals(false, ps2.getLandscape());
wb1.close();
wb2.close();
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestSXSSFWorkbook method bug53515.
@Ignore("currently writing the same sheet multiple times is not supported...")
@Test
public void bug53515() throws Exception {
Workbook wb1 = new SXSSFWorkbook(10);
populateWorkbook(wb1);
saveTwice(wb1);
Workbook wb2 = new XSSFWorkbook();
populateWorkbook(wb2);
saveTwice(wb2);
wb2.close();
wb1.close();
}
Aggregations