Search in sources :

Example 1 with HSSFSeries

use of org.apache.poi.hssf.usermodel.HSSFChart.HSSFSeries in project poi by apache.

the class TestHSSFChart method testExistingSheet3.

@Test
public void testExistingSheet3() throws Exception {
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49581.xls");
    HSSFSheet sheet = wb.getSheetAt(2);
    HSSFChart[] charts = HSSFChart.getSheetCharts(sheet);
    assertEquals(1, charts.length);
    for (HSSFChart chart : charts) {
        for (HSSFSeries series : chart.getSeries()) {
            chart.removeSeries(series);
        }
    }
    // Save and re-check
    wb = HSSFITestDataProvider.instance.writeOutAndReadBack(wb);
    sheet = wb.getSheetAt(2);
    assertEquals(1, HSSFChart.getSheetCharts(sheet).length);
    HSSFChart c = HSSFChart.getSheetCharts(sheet)[0];
    assertEquals(0, c.getSeries().length);
}
Also used : HSSFSeries(org.apache.poi.hssf.usermodel.HSSFChart.HSSFSeries) Test(org.junit.Test)

Example 2 with HSSFSeries

use of org.apache.poi.hssf.usermodel.HSSFChart.HSSFSeries in project poi by apache.

the class TestHSSFChart method testExistingSheet1.

@Test
public void testExistingSheet1() throws Exception {
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49581.xls");
    HSSFSheet sheet = wb.getSheetAt(0);
    HSSFChart[] charts = HSSFChart.getSheetCharts(sheet);
    for (HSSFChart chart : charts) {
        //System.out.println( chart.getType() ) ;
        HSSFSeries[] seriesArray = chart.getSeries();
        //System.out.println( "seriesArray.length=" + seriesArray.length ) ;
        for (HSSFSeries series : seriesArray) {
            //System.out.println( "serie.getNumValues()=" + series.getNumValues() ) ;
            CellRangeAddressBase range;
            range = series.getValuesCellRange();
            //System.out.println( range.toString() ) ;
            range.setLastRow(range.getLastRow() + 1);
            series.setValuesCellRange(range);
            range = series.getCategoryLabelsCellRange();
            //System.out.println( range.toString() ) ;
            range.setLastRow(range.getLastRow() + 1);
            series.setCategoryLabelsCellRange(range);
        }
        for (int id = 0; id < 2; id++) {
            HSSFSeries newSeries = chart.createSeries();
            newSeries.setValuesCellRange(new CellRangeAddress(1 + id, 4, 3, 3));
            String oldSeriesTitle = newSeries.getSeriesTitle();
            if (oldSeriesTitle != null) {
                //System.out.println( "old series title: " + oldSeriesTitle ) ;
                newSeries.setSeriesTitle("new series");
            }
        }
    }
    HSSFChart chart = charts[2];
    chart.removeSeries(chart.getSeries()[0]);
}
Also used : HSSFSeries(org.apache.poi.hssf.usermodel.HSSFChart.HSSFSeries) CellRangeAddressBase(org.apache.poi.ss.util.CellRangeAddressBase) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Test(org.junit.Test)

Example 3 with HSSFSeries

use of org.apache.poi.hssf.usermodel.HSSFChart.HSSFSeries in project poi by apache.

the class TestHSSFChart method testExistingSheet2.

@Test
public void testExistingSheet2() throws Exception {
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49581.xls");
    HSSFSheet sheet = wb.getSheetAt(1);
    HSSFChart[] charts = HSSFChart.getSheetCharts(sheet);
    assertEquals(1, charts.length);
    for (HSSFChart chart : charts) {
        HSSFSeries series;
        // Starts with one
        assertEquals(1, chart.getSeries().length);
        // Add two more
        series = chart.createSeries();
        series.setCategoryLabelsCellRange(new CellRangeAddress(3, 4, 0, 0));
        series.setValuesCellRange(new CellRangeAddress(3, 4, 1, 1));
        series = chart.createSeries();
        series.setCategoryLabelsCellRange(new CellRangeAddress(6, 7, 0, 0));
        series.setValuesCellRange(new CellRangeAddress(6, 7, 1, 1));
    }
    // Save and re-check
    wb = HSSFITestDataProvider.instance.writeOutAndReadBack(wb);
    sheet = wb.getSheetAt(1);
    assertEquals(1, HSSFChart.getSheetCharts(sheet).length);
    HSSFChart c = HSSFChart.getSheetCharts(sheet)[0];
    assertEquals(3, c.getSeries().length);
}
Also used : HSSFSeries(org.apache.poi.hssf.usermodel.HSSFChart.HSSFSeries) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Test(org.junit.Test)

Aggregations

HSSFSeries (org.apache.poi.hssf.usermodel.HSSFChart.HSSFSeries)3 Test (org.junit.Test)3 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)2 CellRangeAddressBase (org.apache.poi.ss.util.CellRangeAddressBase)1