use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class TestLoadSaveXSSF method testLoadPictures.
// TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successful.
public void testLoadPictures() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook(_ssSampels.openResourceAsStream("picture.xlsx"));
List<XSSFPictureData> pictures = workbook.getAllPictures();
assertEquals(1, pictures.size());
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class TestLoadSaveXSSF method testLoadStyles.
// TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successful.
public void testLoadStyles() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook(_ssSampels.openResourceAsStream("styles.xlsx"));
Sheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(0);
Cell cell = row.getCell((short) 0);
CellStyle style = cell.getCellStyle();
// assertNotNull(style);
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class TestCalculationChain method test46535.
public void test46535() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("46535.xlsx");
CalculationChain chain = wb.getCalculationChain();
//the bean holding the reference to the formula to be deleted
CTCalcCell c = chain.getCTCalcChain().getCArray(0);
int cnt = chain.getCTCalcChain().sizeOfCArray();
assertEquals(10, c.getI());
assertEquals("E1", c.getR());
XSSFSheet sheet = wb.getSheet("Test");
XSSFCell cell = sheet.getRow(0).getCell(4);
assertEquals(CellType.FORMULA, cell.getCellTypeEnum());
cell.setCellFormula(null);
//the count of items is less by one
c = chain.getCTCalcChain().getCArray(0);
int cnt2 = chain.getCTCalcChain().sizeOfCArray();
assertEquals(cnt - 1, cnt2);
//the first item in the calculation chain is the former second one
assertEquals(10, c.getI());
assertEquals("C1", c.getR());
assertEquals(CellType.STRING, cell.getCellTypeEnum());
cell.setCellValue("ABC");
assertEquals(CellType.STRING, cell.getCellTypeEnum());
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class TestCommentsTable method readWriteMultipleAuthors.
@Test
public void readWriteMultipleAuthors() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
XSSFSheet sheet1 = workbook.getSheetAt(0);
XSSFSheet sheet2 = workbook.getSheetAt(1);
assertTrue(sheet1.hasComments());
assertFalse(sheet2.hasComments());
assertEquals("Nick Burch", sheet1.getRow(4).getCell(2).getCellComment().getAuthor());
assertEquals("Nick Burch", sheet1.getRow(6).getCell(2).getCellComment().getAuthor());
assertEquals("Torchbox", sheet1.getRow(12).getCell(2).getCellComment().getAuthor());
// Save, and re-load the file
workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
// Check we still have comments where we should do
sheet1 = workbook.getSheetAt(0);
assertNotNull(sheet1.getRow(4).getCell(2).getCellComment());
assertNotNull(sheet1.getRow(6).getCell(2).getCellComment());
assertNotNull(sheet1.getRow(12).getCell(2).getCellComment());
// And check they still have the contents they should do
assertEquals("Nick Burch", sheet1.getRow(4).getCell(2).getCellComment().getAuthor());
assertEquals("Nick Burch", sheet1.getRow(6).getCell(2).getCellComment().getAuthor());
assertEquals("Torchbox", sheet1.getRow(12).getCell(2).getCellComment().getAuthor());
// Todo - check text too, once bug fixed
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class TestCommentsTable method writeRead.
@Test
public void writeRead() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx");
XSSFSheet sheet1 = workbook.getSheetAt(0);
XSSFSheet sheet2 = workbook.getSheetAt(1);
assertTrue(sheet1.hasComments());
assertFalse(sheet2.hasComments());
// Change on comment on sheet 1, and add another into
// sheet 2
Row r5 = sheet1.getRow(4);
Comment cc5 = r5.getCell(2).getCellComment();
cc5.setAuthor("Apache POI");
cc5.setString(new XSSFRichTextString("Hello!"));
Row r2s2 = sheet2.createRow(2);
Cell c1r2s2 = r2s2.createCell(1);
assertNull(c1r2s2.getCellComment());
Drawing<?> dg = sheet2.createDrawingPatriarch();
Comment cc2 = dg.createCellComment(new XSSFClientAnchor());
cc2.setAuthor("Also POI");
cc2.setString(new XSSFRichTextString("A new comment"));
c1r2s2.setCellComment(cc2);
// Save, and re-load the file
workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
// Check we still have comments where we should do
sheet1 = workbook.getSheetAt(0);
sheet2 = workbook.getSheetAt(1);
assertNotNull(sheet1.getRow(4).getCell(2).getCellComment());
assertNotNull(sheet1.getRow(6).getCell(2).getCellComment());
assertNotNull(sheet2.getRow(2).getCell(1).getCellComment());
// And check they still have the contents they should do
assertEquals("Apache POI", sheet1.getRow(4).getCell(2).getCellComment().getAuthor());
assertEquals("Nick Burch", sheet1.getRow(6).getCell(2).getCellComment().getAuthor());
assertEquals("Also POI", sheet2.getRow(2).getCell(1).getCellComment().getAuthor());
assertEquals("Hello!", sheet1.getRow(4).getCell(2).getCellComment().getString().getString());
}
Aggregations