use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestRegionUtil method getCellStyle.
private CellStyle getCellStyle(int rowIndex, int columnIndex) {
Row row = sheet.getRow(rowIndex);
if (row == null)
row = sheet.createRow(rowIndex);
Cell cell = row.getCell(columnIndex);
if (cell == null)
cell = row.createCell(columnIndex);
return cell.getCellStyle();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestSheetUtil method testGetCellWidthNumber.
public void testGetCellWidthNumber() throws IOException {
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("sheet");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue(88.234);
assertTrue(SheetUtil.getCellWidth(cell, 1, null, true) > 0);
wb.close();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestSheetUtil method testCellWithMerges.
public void testCellWithMerges() throws Exception {
Workbook wb = new HSSFWorkbook();
Sheet s = wb.createSheet();
// Create some test data
Row r2 = s.createRow(1);
r2.createCell(0).setCellValue(10);
r2.createCell(1).setCellValue(11);
Row r3 = s.createRow(2);
r3.createCell(0).setCellValue(20);
r3.createCell(1).setCellValue(21);
s.addMergedRegion(new CellRangeAddress(2, 3, 0, 0));
s.addMergedRegion(new CellRangeAddress(2, 2, 1, 4));
// With a cell that isn't defined, we'll get null
assertEquals(null, SheetUtil.getCellWithMerges(s, 0, 0));
// With a cell that's not in a merged region, we'll get that
assertEquals(10.0, SheetUtil.getCellWithMerges(s, 1, 0).getNumericCellValue());
assertEquals(11.0, SheetUtil.getCellWithMerges(s, 1, 1).getNumericCellValue());
// With a cell that's the primary one of a merged region, we get that cell
assertEquals(20.0, SheetUtil.getCellWithMerges(s, 2, 0).getNumericCellValue());
assertEquals(21., SheetUtil.getCellWithMerges(s, 2, 1).getNumericCellValue());
// With a cell elsewhere in the merged region, get top-left
assertEquals(20.0, SheetUtil.getCellWithMerges(s, 3, 0).getNumericCellValue());
assertEquals(21.0, SheetUtil.getCellWithMerges(s, 2, 2).getNumericCellValue());
assertEquals(21.0, SheetUtil.getCellWithMerges(s, 2, 3).getNumericCellValue());
assertEquals(21.0, SheetUtil.getCellWithMerges(s, 2, 4).getNumericCellValue());
wb.close();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestBugs method bug53404.
@Test
public void bug53404() throws Exception {
HSSFWorkbook wb = openSample("53404.xls");
Sheet sheet = wb.getSheet("test-sheet");
int rowCount = sheet.getLastRowNum() + 1;
int newRows = 5;
Calendar cal = LocaleUtil.getLocaleCalendar();
for (int r = rowCount; r < rowCount + newRows; r++) {
Row row = sheet.createRow((short) r);
row.createCell(0).setCellValue(1.03 * (r + 7));
row.createCell(1).setCellValue(cal.getTime());
row.createCell(2).setCellValue(cal);
row.createCell(3).setCellValue(String.format(Locale.ROOT, "row:%d/col:%d", r, 3));
row.createCell(4).setCellValue(true);
row.createCell(5).setCellType(CellType.ERROR);
row.createCell(6).setCellValue("added cells.");
}
writeOutAndReadBack(wb).close();
wb.close();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestBugs method test57925.
@Test
public void test57925() throws IOException {
Workbook wb = HSSFTestDataSamples.openSampleWorkbook("57925.xls");
wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
Sheet sheet = wb.getSheetAt(i);
for (Row row : sheet) {
for (Cell cell : row) {
new DataFormatter().formatCellValue(cell);
}
}
}
wb.close();
}
Aggregations