use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestUnfixedBugs method testBug54084Unicode.
@Test
public void testBug54084Unicode() throws IOException {
// sample XLSX with the same text-contents as the text-file above
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("54084 - Greek - beyond BMP.xlsx");
verifyBug54084Unicode(wb);
// OutputStream baos = new FileOutputStream("/tmp/test.xlsx");
// try {
// wb.write(baos);
// } finally {
// baos.close();
// }
// now write the file and read it back in
XSSFWorkbook wbWritten = XSSFTestDataSamples.writeOutAndReadBack(wb);
verifyBug54084Unicode(wbWritten);
// finally also write it out via the streaming interface and verify that we still can read it back in
SXSSFWorkbook swb = new SXSSFWorkbook(wb);
Workbook wbStreamingWritten = SXSSFITestDataProvider.instance.writeOutAndReadBack(swb);
verifyBug54084Unicode(wbStreamingWritten);
wbWritten.close();
swb.close();
wbStreamingWritten.close();
wb.close();
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestUnfixedBugs method test54071.
@Test
public void test54071() throws Exception {
Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("54071.xlsx");
Sheet sheet = workbook.getSheetAt(0);
int rows = sheet.getPhysicalNumberOfRows();
System.out.println(">> file rows is:" + (rows - 1) + " <<");
Row title = sheet.getRow(0);
Date prev = null;
for (int row = 1; row < rows; row++) {
Row rowObj = sheet.getRow(row);
for (int col = 0; col < 1; col++) {
String titleName = title.getCell(col).toString();
Cell cell = rowObj.getCell(col);
if (titleName.startsWith("time")) {
// here the output will produce ...59 or ...58 for the rows, probably POI is
// doing some different rounding or some other small difference...
System.out.println("==Time:" + cell.getDateCellValue());
if (prev != null) {
assertEquals(prev, cell.getDateCellValue());
}
prev = cell.getDateCellValue();
}
}
}
workbook.close();
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestUnfixedBugs method testBug55752.
@Test
public void testBug55752() throws IOException {
Workbook wb = new XSSFWorkbook();
try {
Sheet sheet = wb.createSheet("test");
for (int i = 0; i < 4; i++) {
Row row = sheet.createRow(i);
for (int j = 0; j < 2; j++) {
Cell cell = row.createCell(j);
cell.setCellStyle(wb.createCellStyle());
}
}
// set content
Row row1 = sheet.getRow(0);
row1.getCell(0).setCellValue("AAA");
Row row2 = sheet.getRow(1);
row2.getCell(0).setCellValue("BBB");
Row row3 = sheet.getRow(2);
row3.getCell(0).setCellValue("CCC");
Row row4 = sheet.getRow(3);
row4.getCell(0).setCellValue("DDD");
// merge cells
CellRangeAddress range1 = new CellRangeAddress(0, 0, 0, 1);
sheet.addMergedRegion(range1);
CellRangeAddress range2 = new CellRangeAddress(1, 1, 0, 1);
sheet.addMergedRegion(range2);
CellRangeAddress range3 = new CellRangeAddress(2, 2, 0, 1);
sheet.addMergedRegion(range3);
assertEquals(0, range3.getFirstColumn());
assertEquals(1, range3.getLastColumn());
assertEquals(2, range3.getLastRow());
CellRangeAddress range4 = new CellRangeAddress(3, 3, 0, 1);
sheet.addMergedRegion(range4);
// set border
RegionUtil.setBorderBottom(CellStyle.BORDER_THIN, range1, sheet, wb);
row2.getCell(0).getCellStyle().setBorderBottom(CellStyle.BORDER_THIN);
row2.getCell(1).getCellStyle().setBorderBottom(CellStyle.BORDER_THIN);
Cell cell0 = CellUtil.getCell(row3, 0);
CellUtil.setCellStyleProperty(cell0, CellUtil.BORDER_BOTTOM, CellStyle.BORDER_THIN);
Cell cell1 = CellUtil.getCell(row3, 1);
CellUtil.setCellStyleProperty(cell1, CellUtil.BORDER_BOTTOM, CellStyle.BORDER_THIN);
RegionUtil.setBorderBottom(CellStyle.BORDER_THIN, range4, sheet, wb);
// write to file
OutputStream stream = new FileOutputStream(new File("C:/temp/55752.xlsx"));
try {
wb.write(stream);
} finally {
stream.close();
}
} finally {
wb.close();
}
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestSXSSFSheet method overrideFlushedRows.
@Test
public void overrideFlushedRows() throws IOException {
Workbook wb = new SXSSFWorkbook(3);
try {
Sheet sheet = wb.createSheet();
sheet.createRow(1);
sheet.createRow(2);
sheet.createRow(3);
sheet.createRow(4);
thrown.expect(Throwable.class);
thrown.expectMessage("Attempting to write a row[1] in the range [0,1] that is already written to disk.");
sheet.createRow(1);
} finally {
wb.close();
}
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestXSSFComment method testBug58175a.
@Ignore("Used for manual testing with opening the resulting Workbook in Excel")
@Test
public void testBug58175a() throws IOException {
Workbook wb = new SXSSFWorkbook();
try {
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(1);
Cell cell = row.createCell(3);
cell.setCellValue("F4");
Drawing<?> drawing = sheet.createDrawingPatriarch();
CreationHelper factory = wb.getCreationHelper();
// When the comment box is visible, have it show in a 1x3 space
ClientAnchor anchor = factory.createClientAnchor();
anchor.setCol1(cell.getColumnIndex());
anchor.setCol2(cell.getColumnIndex() + 1);
anchor.setRow1(row.getRowNum());
anchor.setRow2(row.getRowNum() + 3);
// Create the comment and set the text+author
Comment comment = drawing.createCellComment(anchor);
RichTextString str = factory.createRichTextString("Hello, World!");
comment.setString(str);
comment.setAuthor("Apache POI");
/* fixed the problem as well
* comment.setColumn(cell.getColumnIndex());
* comment.setRow(cell.getRowIndex());
*/
// Assign the comment to the cell
cell.setCellComment(comment);
OutputStream out = new FileOutputStream("C:\\temp\\58175.xlsx");
try {
wb.write(out);
} finally {
out.close();
}
} finally {
wb.close();
}
}
Aggregations