use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestUnfixedBugs method testFormulaRecordAggregate.
@Test
public void testFormulaRecordAggregate() throws Exception {
// fails at formula "=MEHRFACH.OPERATIONEN(E$3;$B$5;$D4)"
Workbook wb = HSSFTestDataSamples.openSampleWorkbook("44958.xls");
try {
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
Sheet sheet = wb.getSheetAt(i);
assertNotNull(wb.getSheet(sheet.getSheetName()));
sheet.groupColumn((short) 4, (short) 5);
sheet.setColumnGroupCollapsed(4, true);
sheet.setColumnGroupCollapsed(4, false);
for (Row row : sheet) {
for (Cell cell : row) {
try {
cell.toString();
} catch (Exception e) {
throw new Exception("While handling: " + sheet.getSheetName() + "/" + row.getRowNum() + "/" + cell.getColumnIndex(), e);
}
}
}
}
} finally {
wb.close();
}
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestHSSFWorkbook method testRewriteFileBug58480.
@Test
public void testRewriteFileBug58480() throws IOException {
final File file = TempFile.createTempFile("TestHSSFWorkbook", ".xls");
try {
// create new workbook
{
final Workbook workbook = new HSSFWorkbook();
final Sheet sheet = workbook.createSheet("foo");
final Row row = sheet.createRow(1);
row.createCell(1).setCellValue("bar");
writeAndCloseWorkbook(workbook, file);
}
// edit the workbook
{
NPOIFSFileSystem fs = new NPOIFSFileSystem(file, false);
try {
DirectoryNode root = fs.getRoot();
final Workbook workbook = new HSSFWorkbook(root, true);
final Sheet sheet = workbook.getSheet("foo");
sheet.getRow(1).createCell(2).setCellValue("baz");
writeAndCloseWorkbook(workbook, file);
} finally {
fs.close();
}
}
} finally {
assertTrue(file.exists());
assertTrue(file.delete());
}
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestHSSFWorkbook method cellStylesLimit.
@Test
public void cellStylesLimit() throws IOException {
Workbook wb = new HSSFWorkbook();
int numBuiltInStyles = wb.getNumCellStyles();
int MAX_STYLES = 4030;
int limit = MAX_STYLES - numBuiltInStyles;
for (int i = 0; i < limit; i++) {
/* HSSFCellStyle style =*/
wb.createCellStyle();
}
assertEquals(MAX_STYLES, wb.getNumCellStyles());
try {
/*HSSFCellStyle style =*/
wb.createCellStyle();
fail("expected exception");
} catch (IllegalStateException e) {
assertEquals("The maximum number of cell styles was exceeded. " + "You can define up to 4000 styles in a .xls workbook", e.getMessage());
}
assertEquals(MAX_STYLES, wb.getNumCellStyles());
wb.close();
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestHSSFWorkbook method closeDoesNotModifyWorkbook.
@Test
public void closeDoesNotModifyWorkbook() throws IOException {
final String filename = "SampleSS.xls";
final File file = POIDataSamples.getSpreadSheetInstance().getFile(filename);
Workbook wb;
// File via POIFileStream (java.io)
wb = new HSSFWorkbook(new POIFSFileSystem(file));
assertCloseDoesNotModifyFile(filename, wb);
// File via NPOIFileStream (java.nio)
wb = new HSSFWorkbook(new NPOIFSFileSystem(file));
assertCloseDoesNotModifyFile(filename, wb);
// InputStream
wb = new HSSFWorkbook(new FileInputStream(file));
assertCloseDoesNotModifyFile(filename, wb);
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestCellFormat method testApplyFormatHasThreePartsFirstTwoHaveCondition.
@Test
public void testApplyFormatHasThreePartsFirstTwoHaveCondition() throws Exception {
// Create a workbook, row and cell to test with
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
CellFormat cf = CellFormat.getInstance("[>=100]0.00;[>=10]0.000;0.0000");
cell.setCellValue(100);
assertEquals("100.00", cf.apply(cell).text);
cell.setCellValue(10);
assertEquals("10.000", cf.apply(cell).text);
cell.setCellValue(0);
assertEquals("0.0000", cf.apply(cell).text);
cell.setCellValue(-10);
assertEquals("-10.0000", cf.apply(cell).text);
cell.setCellValue("abc");
assertEquals("abc", cf.apply(cell).text);
wb.close();
}
Aggregations