Search in sources :

Example 56 with Workbook

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();
}
Also used : ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ChartLegend(org.apache.poi.ss.usermodel.charts.ChartLegend) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Chart(org.apache.poi.ss.usermodel.Chart) Test(org.junit.Test)

Example 57 with Workbook

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();
}
Also used : ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ChartLegend(org.apache.poi.ss.usermodel.charts.ChartLegend) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Chart(org.apache.poi.ss.usermodel.Chart) Test(org.junit.Test)

Example 58 with Workbook

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);
    }
}
Also used : IOException(java.io.IOException) BaseTestXWorkbook(org.apache.poi.ss.usermodel.BaseTestXWorkbook) CTWorkbook(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 59 with Workbook

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();
}
Also used : BaseTestXWorkbook(org.apache.poi.ss.usermodel.BaseTestXWorkbook) CTWorkbook(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 60 with Workbook

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();
}
Also used : SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) BaseTestXSheet(org.apache.poi.ss.usermodel.BaseTestXSheet) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFTestDataSamples.openSampleWorkbook(org.apache.poi.xssf.XSSFTestDataSamples.openSampleWorkbook) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook)

Aggregations

Workbook (org.apache.poi.ss.usermodel.Workbook)319 Sheet (org.apache.poi.ss.usermodel.Sheet)224 Test (org.junit.Test)207 Cell (org.apache.poi.ss.usermodel.Cell)140 Row (org.apache.poi.ss.usermodel.Row)123 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)104 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)95 FileOutputStream (java.io.FileOutputStream)33 XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)32 ByteArrayInputStream (java.io.ByteArrayInputStream)30 FormulaEvaluator (org.apache.poi.ss.usermodel.FormulaEvaluator)30 XSSFDrawing (org.apache.poi.xssf.usermodel.XSSFDrawing)27 CTChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTChart)27 File (java.io.File)26 CellStyle (org.apache.poi.ss.usermodel.CellStyle)25 InternalWorkbook (org.apache.poi.hssf.model.InternalWorkbook)24 LangYearFilterPagingRequest (org.devgateway.ocds.web.rest.controller.request.LangYearFilterPagingRequest)23 IOException (java.io.IOException)22 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)18 FileInputStream (java.io.FileInputStream)15