Search in sources :

Example 11 with ClientAnchor

use of org.apache.poi.ss.usermodel.ClientAnchor 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 12 with ClientAnchor

use of org.apache.poi.ss.usermodel.ClientAnchor 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 13 with ClientAnchor

use of org.apache.poi.ss.usermodel.ClientAnchor 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 14 with ClientAnchor

use of org.apache.poi.ss.usermodel.ClientAnchor in project poi by apache.

the class CellComments method main.

public static void main(String[] args) throws IOException {
    Workbook wb = new XSSFWorkbook();
    CreationHelper factory = wb.getCreationHelper();
    Sheet sheet = wb.createSheet();
    Cell cell1 = sheet.createRow(3).createCell(5);
    cell1.setCellValue("F4");
    Drawing<?> drawing = sheet.createDrawingPatriarch();
    ClientAnchor anchor = factory.createClientAnchor();
    Comment comment1 = drawing.createCellComment(anchor);
    RichTextString str1 = factory.createRichTextString("Hello, World!");
    comment1.setString(str1);
    comment1.setAuthor("Apache POI");
    cell1.setCellComment(comment1);
    Cell cell2 = sheet.createRow(2).createCell(2);
    cell2.setCellValue("C3");
    Comment comment2 = drawing.createCellComment(anchor);
    RichTextString str2 = factory.createRichTextString("XSSF can set cell comments");
    //apply custom font to the text in the comment
    Font font = wb.createFont();
    font.setFontName("Arial");
    font.setFontHeightInPoints((short) 14);
    font.setBold(true);
    font.setColor(IndexedColors.RED.getIndex());
    str2.applyFont(font);
    comment2.setString(str2);
    comment2.setAuthor("Apache POI");
    comment2.setAddress(new CellAddress("C3"));
    String fname = "comments.xlsx";
    FileOutputStream out = new FileOutputStream(fname);
    wb.write(out);
    out.close();
    wb.close();
}
Also used : Comment(org.apache.poi.ss.usermodel.Comment) CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) RichTextString(org.apache.poi.ss.usermodel.RichTextString) RichTextString(org.apache.poi.ss.usermodel.RichTextString) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Font(org.apache.poi.ss.usermodel.Font) CellAddress(org.apache.poi.ss.util.CellAddress) ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) FileOutputStream(java.io.FileOutputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell)

Example 15 with ClientAnchor

use of org.apache.poi.ss.usermodel.ClientAnchor in project poi by apache.

the class ScatterChart method main.

public static void main(String[] args) throws IOException {
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet("Sheet 1");
    final int NUM_OF_ROWS = 3;
    final int NUM_OF_COLUMNS = 10;
    // Create a row and put some cells in it. Rows are 0 based.
    Row row;
    Cell cell;
    for (int rowIndex = 0; rowIndex < NUM_OF_ROWS; rowIndex++) {
        row = sheet.createRow((short) rowIndex);
        for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++) {
            cell = row.createCell((short) colIndex);
            cell.setCellValue(colIndex * (rowIndex + 1));
        }
    }
    Drawing<?> drawing = sheet.createDrawingPatriarch();
    ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);
    Chart chart = drawing.createChart(anchor);
    ChartLegend legend = chart.getOrCreateLegend();
    legend.setPosition(LegendPosition.TOP_RIGHT);
    ScatterChartData data = chart.getChartDataFactory().createScatterChartData();
    ValueAxis bottomAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
    ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
    leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
    ChartDataSource<Number> xs = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
    ChartDataSource<Number> ys1 = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1));
    ChartDataSource<Number> ys2 = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(2, 2, 0, NUM_OF_COLUMNS - 1));
    data.addSerie(xs, ys1);
    data.addSerie(xs, ys2);
    chart.plot(data, bottomAxis, leftAxis);
    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream("ooxml-scatter-chart.xlsx");
    wb.write(fileOut);
    fileOut.close();
    wb.close();
}
Also used : ChartLegend(org.apache.poi.ss.usermodel.charts.ChartLegend) ScatterChartData(org.apache.poi.ss.usermodel.charts.ScatterChartData) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) ValueAxis(org.apache.poi.ss.usermodel.charts.ValueAxis) FileOutputStream(java.io.FileOutputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Row(org.apache.poi.ss.usermodel.Row) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) Chart(org.apache.poi.ss.usermodel.Chart)

Aggregations

ClientAnchor (org.apache.poi.ss.usermodel.ClientAnchor)25 Sheet (org.apache.poi.ss.usermodel.Sheet)16 Workbook (org.apache.poi.ss.usermodel.Workbook)13 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)12 Test (org.junit.Test)12 Chart (org.apache.poi.ss.usermodel.Chart)11 Cell (org.apache.poi.ss.usermodel.Cell)9 ChartLegend (org.apache.poi.ss.usermodel.charts.ChartLegend)8 CreationHelper (org.apache.poi.ss.usermodel.CreationHelper)7 Row (org.apache.poi.ss.usermodel.Row)7 FileOutputStream (java.io.FileOutputStream)5 Comment (org.apache.poi.ss.usermodel.Comment)5 RichTextString (org.apache.poi.ss.usermodel.RichTextString)5 ChartAxis (org.apache.poi.ss.usermodel.charts.ChartAxis)5 ValueAxis (org.apache.poi.ss.usermodel.charts.ValueAxis)4 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)4 LineChartData (org.apache.poi.ss.usermodel.charts.LineChartData)3 ScatterChartData (org.apache.poi.ss.usermodel.charts.ScatterChartData)3 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)3 Dimension (java.awt.Dimension)2