use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestXSSFChartLegend method testLegendPositionAccessMethods.
@Test
public void testLegendPositionAccessMethods() throws IOException {
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet();
Drawing<?> drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
Chart chart = drawing.createChart(anchor);
ChartLegend legend = chart.getOrCreateLegend();
legend.setPosition(LegendPosition.TOP_RIGHT);
assertEquals(LegendPosition.TOP_RIGHT, legend.getPosition());
wb.close();
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestXSSFChartLegend method test_setOverlay_chartLegendSetToTrue_expectOverlayInitialValueSetToTrue.
@Test
public void test_setOverlay_chartLegendSetToTrue_expectOverlayInitialValueSetToTrue() throws IOException {
// Arrange
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet();
Drawing<?> drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
Chart chart = drawing.createChart(anchor);
ChartLegend legend = chart.getOrCreateLegend();
// Act
legend.setOverlay(true);
// Assert
assertTrue(legend.isOverlay());
wb.close();
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestXSSFWorkbook method testCloseBeforeWrite.
@Test
public void testCloseBeforeWrite() throws IOException {
Workbook wb = new XSSFWorkbook();
wb.createSheet("somesheet");
// test what happens if we close the Workbook before we write it out
wb.close();
try {
XSSFTestDataSamples.writeOutAndReadBack(wb);
fail("Expecting IOException here");
} catch (RuntimeException e) {
// expected here
assertTrue("Had: " + e.getCause(), e.getCause() instanceof IOException);
}
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestXSSFWorkbook method bug47090c.
@Test
public void bug47090c() throws IOException {
Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx");
assertSheetOrder(workbook, "Sheet1", "Sheet2");
workbook.removeSheetAt(0);
assertSheetOrder(workbook, "Sheet2");
workbook.cloneSheet(0);
assertSheetOrder(workbook, "Sheet2", "Sheet2 (2)");
Workbook read = XSSFTestDataSamples.writeOutAndReadBack(workbook);
assertSheetOrder(read, "Sheet2", "Sheet2 (2)");
read.close();
workbook.close();
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestXSSFSheet method runGetTopRow.
private void runGetTopRow(String file, boolean isXSSF, int... topRows) throws IOException {
final Workbook wb = (isXSSF) ? XSSFTestDataSamples.openSampleWorkbook(file) : HSSFTestDataSamples.openSampleWorkbook(file);
for (int si = 0; si < wb.getNumberOfSheets(); si++) {
Sheet sh = wb.getSheetAt(si);
assertNotNull(sh.getSheetName());
assertEquals("Did not match for sheet " + si, topRows[si], sh.getTopRow());
}
// for XSSF also test with SXSSF
if (isXSSF) {
Workbook swb = new SXSSFWorkbook((XSSFWorkbook) wb);
for (int si = 0; si < swb.getNumberOfSheets(); si++) {
Sheet sh = swb.getSheetAt(si);
assertNotNull(sh.getSheetName());
assertEquals("Did not match for sheet " + si, topRows[si], sh.getTopRow());
}
swb.close();
}
wb.close();
}
Aggregations