Search in sources :

Example 1 with SheetBuilder

use of org.apache.poi.ss.util.SheetBuilder in project poi by apache.

the class TestXSSFLineChartData method testOneSeriePlot.

@Test
public void testOneSeriePlot() throws IOException {
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = new SheetBuilder(wb, plotData).build();
    Drawing<?> drawing = sheet.createDrawingPatriarch();
    ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
    Chart chart = drawing.createChart(anchor);
    ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
    ChartAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
    LineChartData lineChartData = chart.getChartDataFactory().createLineChartData();
    ChartDataSource<String> xs = DataSources.fromStringCellRange(sheet, CellRangeAddress.valueOf("A1:J1"));
    ChartDataSource<Number> ys = DataSources.fromNumericCellRange(sheet, CellRangeAddress.valueOf("A2:J2"));
    LineChartSeries series = lineChartData.addSeries(xs, ys);
    assertNotNull(series);
    assertEquals(1, lineChartData.getSeries().size());
    assertTrue(lineChartData.getSeries().contains(series));
    chart.plot(lineChartData, bottomAxis, leftAxis);
    wb.close();
}
Also used : SheetBuilder(org.apache.poi.ss.util.SheetBuilder) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) LineChartData(org.apache.poi.ss.usermodel.charts.LineChartData) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) LineChartSeries(org.apache.poi.ss.usermodel.charts.LineChartSeries) Chart(org.apache.poi.ss.usermodel.Chart) Test(org.junit.Test)

Example 2 with SheetBuilder

use of org.apache.poi.ss.util.SheetBuilder in project poi by apache.

the class TestCellWalk method testNotTraverseEmptyCells.

public void testNotTraverseEmptyCells() {
    Workbook wb = new HSSFWorkbook();
    Sheet sheet = new SheetBuilder(wb, testData).build();
    CellRangeAddress range = CellRangeAddress.valueOf("A1:C3");
    CellWalk cellWalk = new CellWalk(sheet, range);
    countCellHandler.reset();
    cellWalk.traverse(countCellHandler);
    assertEquals(4, countCellHandler.getVisitedCellsNumber());
    /* 1 + 2 + 5 + 9 */
    assertEquals(17L, countCellHandler.getOrdinalNumberSum());
}
Also used : SheetBuilder(org.apache.poi.ss.util.SheetBuilder) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 3 with SheetBuilder

use of org.apache.poi.ss.util.SheetBuilder in project poi by apache.

the class TestDataSources method testMixedCellDataSource.

public void testMixedCellDataSource() {
    Workbook wb = new HSSFWorkbook();
    Sheet sheet = new SheetBuilder(wb, mixedCells).build();
    CellRangeAddress mixedCellRange = CellRangeAddress.valueOf("A1:F1");
    ChartDataSource<String> strDataSource = DataSources.fromStringCellRange(sheet, mixedCellRange);
    ChartDataSource<Number> numDataSource = DataSources.fromNumericCellRange(sheet, mixedCellRange);
    for (int i = 0; i < mixedCells[0].length; ++i) {
        if (i % 2 == 0) {
            assertNull(strDataSource.getPointAt(i));
            assertEquals(((Number) mixedCells[0][i]).doubleValue(), numDataSource.getPointAt(i).doubleValue(), 0.00001);
        } else {
            assertNull(numDataSource.getPointAt(i));
            assertEquals(mixedCells[0][i], strDataSource.getPointAt(i));
        }
    }
}
Also used : SheetBuilder(org.apache.poi.ss.util.SheetBuilder) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 4 with SheetBuilder

use of org.apache.poi.ss.util.SheetBuilder in project poi by apache.

the class TestDataSources method testIOBExceptionOnInvalidIndex.

public void testIOBExceptionOnInvalidIndex() {
    Workbook wb = new HSSFWorkbook();
    Sheet sheet = new SheetBuilder(wb, numericCells).build();
    CellRangeAddress rangeAddress = CellRangeAddress.valueOf("A2:E2");
    ChartDataSource<Number> numDataSource = DataSources.fromNumericCellRange(sheet, rangeAddress);
    IndexOutOfBoundsException exception = null;
    try {
        numDataSource.getPointAt(-1);
    } catch (IndexOutOfBoundsException e) {
        exception = e;
    }
    assertNotNull(exception);
    exception = null;
    try {
        numDataSource.getPointAt(numDataSource.getPointCount());
    } catch (IndexOutOfBoundsException e) {
        exception = e;
    }
    assertNotNull(exception);
}
Also used : SheetBuilder(org.apache.poi.ss.util.SheetBuilder) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 5 with SheetBuilder

use of org.apache.poi.ss.util.SheetBuilder in project poi by apache.

the class TestDataSources method testStringCellDataSource.

public void testStringCellDataSource() {
    Workbook wb = new HSSFWorkbook();
    Sheet sheet = new SheetBuilder(wb, stringCells).build();
    CellRangeAddress numCellRange = CellRangeAddress.valueOf("A2:E2");
    ChartDataSource<String> numDataSource = DataSources.fromStringCellRange(sheet, numCellRange);
    assertTrue(numDataSource.isReference());
    assertFalse(numDataSource.isNumeric());
    assertEquals(numericCells[0].length, numDataSource.getPointCount());
    for (int i = 0; i < stringCells[1].length; ++i) {
        assertEquals(stringCells[1][i], numDataSource.getPointAt(i));
    }
}
Also used : SheetBuilder(org.apache.poi.ss.util.SheetBuilder) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Aggregations

Sheet (org.apache.poi.ss.usermodel.Sheet)7 Workbook (org.apache.poi.ss.usermodel.Workbook)7 SheetBuilder (org.apache.poi.ss.util.SheetBuilder)7 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)5 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)5 Chart (org.apache.poi.ss.usermodel.Chart)2 ClientAnchor (org.apache.poi.ss.usermodel.ClientAnchor)2 ChartAxis (org.apache.poi.ss.usermodel.charts.ChartAxis)2 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)2 Test (org.junit.Test)2 LineChartData (org.apache.poi.ss.usermodel.charts.LineChartData)1 LineChartSeries (org.apache.poi.ss.usermodel.charts.LineChartSeries)1 ScatterChartData (org.apache.poi.ss.usermodel.charts.ScatterChartData)1 ScatterChartSeries (org.apache.poi.ss.usermodel.charts.ScatterChartSeries)1