use of org.apache.poi.ss.usermodel.Row 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.Row 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.Row 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();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestCellFormat method testApplyFormatHasFourPartsSecondHasCondition.
@Test
public void testApplyFormatHasFourPartsSecondHasCondition() 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("0.00;[>=100]0.000;0.0000;~~@~~");
cell.setCellValue(100);
assertEquals("100.00", cf.apply(cell).text);
cell.setCellValue(10);
assertEquals("10.00", cf.apply(cell).text);
cell.setCellValue(0.123456789012345);
assertEquals("0.12", 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);
cell.setCellValue(true);
assertEquals("~~TRUE~~", cf.apply(cell).text);
wb.close();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestCellFormat method testApplyFormatHasThreePartsFirstTwoHaveConditionThirdIsGeneral.
@Test
public void testApplyFormatHasThreePartsFirstTwoHaveConditionThirdIsGeneral() 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;General");
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", cf.apply(cell).text);
cell.setCellValue(-10);
assertEquals("-10", cf.apply(cell).text);
cell.setCellValue("abc");
assertEquals("abc", cf.apply(cell).text);
wb.close();
}
Aggregations