Search in sources :

Example 21 with ClientAnchor

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

the class TestHSSFPicture method bug49658.

@SuppressWarnings("resource")
@Test
public void bug49658() throws IOException {
    // test if inserted EscherMetafileBlip will be read again
    HSSFWorkbook wb = new HSSFWorkbook();
    byte[] pictureDataEmf = POIDataSamples.getDocumentInstance().readFile("vector_image.emf");
    int indexEmf = wb.addPicture(pictureDataEmf, HSSFWorkbook.PICTURE_TYPE_EMF);
    byte[] pictureDataPng = POIDataSamples.getSpreadSheetInstance().readFile("logoKarmokar4.png");
    int indexPng = wb.addPicture(pictureDataPng, HSSFWorkbook.PICTURE_TYPE_PNG);
    byte[] pictureDataWmf = POIDataSamples.getSlideShowInstance().readFile("santa.wmf");
    int indexWmf = wb.addPicture(pictureDataWmf, HSSFWorkbook.PICTURE_TYPE_WMF);
    HSSFSheet sheet = wb.createSheet();
    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
    CreationHelper ch = wb.getCreationHelper();
    ClientAnchor anchor = ch.createClientAnchor();
    anchor.setCol1(2);
    anchor.setCol2(5);
    anchor.setRow1(1);
    anchor.setRow2(6);
    patriarch.createPicture(anchor, indexEmf);
    anchor = ch.createClientAnchor();
    anchor.setCol1(2);
    anchor.setCol2(5);
    anchor.setRow1(10);
    anchor.setRow2(16);
    patriarch.createPicture(anchor, indexPng);
    anchor = ch.createClientAnchor();
    anchor.setCol1(6);
    anchor.setCol2(9);
    anchor.setRow1(1);
    anchor.setRow2(6);
    patriarch.createPicture(anchor, indexWmf);
    wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
    byte[] pictureDataOut = wb.getAllPictures().get(0).getData();
    assertArrayEquals(pictureDataEmf, pictureDataOut);
    byte[] wmfNoHeader = new byte[pictureDataWmf.length - 22];
    System.arraycopy(pictureDataWmf, 22, wmfNoHeader, 0, pictureDataWmf.length - 22);
    pictureDataOut = wb.getAllPictures().get(2).getData();
    assertArrayEquals(wmfNoHeader, pictureDataOut);
    wb.close();
}
Also used : ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) Test(org.junit.Test)

Example 22 with ClientAnchor

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

the class TestXSSFManualLayout method createEmptyLayout.

@Before
public void createEmptyLayout() {
    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();
    layout = legend.getManualLayout();
}
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) Chart(org.apache.poi.ss.usermodel.Chart) Before(org.junit.Before)

Example 23 with ClientAnchor

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

the class TestXSSFScatterChartData 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().createValueAxis(AxisPosition.BOTTOM);
    ChartAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
    ScatterChartData scatterChartData = chart.getChartDataFactory().createScatterChartData();
    ChartDataSource<String> xs = DataSources.fromStringCellRange(sheet, CellRangeAddress.valueOf("A1:J1"));
    ChartDataSource<Number> ys = DataSources.fromNumericCellRange(sheet, CellRangeAddress.valueOf("A2:J2"));
    ScatterChartSeries series = scatterChartData.addSerie(xs, ys);
    assertNotNull(series);
    assertEquals(1, scatterChartData.getSeries().size());
    assertTrue(scatterChartData.getSeries().contains(series));
    chart.plot(scatterChartData, bottomAxis, leftAxis);
    wb.close();
}
Also used : SheetBuilder(org.apache.poi.ss.util.SheetBuilder) ScatterChartData(org.apache.poi.ss.usermodel.charts.ScatterChartData) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) ScatterChartSeries(org.apache.poi.ss.usermodel.charts.ScatterChartSeries) ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) Chart(org.apache.poi.ss.usermodel.Chart) Test(org.junit.Test)

Example 24 with ClientAnchor

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

the class TestXSSFChartLegend method test_setOverlay_defaultChartLegend_expectOverlayInitialValueSetToFalse.

@Test
public void test_setOverlay_defaultChartLegend_expectOverlayInitialValueSetToFalse() 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
    // Assert
    assertFalse(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 25 with ClientAnchor

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

the class ExcelChartSheetDefault method createChartAndLegend.

/**
     * Creates a chart and also attaches a legend to it.
     */
@Override
public Chart createChartAndLegend() {
    final Drawing drawing = excelSheet.createDrawingPatriarch();
    final ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 15, 25);
    final Chart chart = drawing.createChart(anchor);
    final ChartLegend legend = chart.getOrCreateLegend();
    legend.setPosition(LegendPosition.BOTTOM);
    return chart;
}
Also used : Drawing(org.apache.poi.ss.usermodel.Drawing) ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) ChartLegend(org.apache.poi.ss.usermodel.charts.ChartLegend) 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