Search code examples
javaapache-poixssf

How to resize POI XSSFChart


So i get chart from excel file (.xlsx) by this code.

XSSFSheet sheet = workbook.getSheetAt(10);
XSSFDrawing drawing = sheet.createDrawingPatriarch();
XSSFChart chart = drawing.getCharts().get(0);

and i need to resize this chart like

chart.setHeight(100);

Solution

  • Using CTMarker and XSSFDrawing, you shall resize with the coordinates as below.

    XSSFDrawing draw= ((XSSFSheet)currentSheet).createDrawingPatriarch();
    CTMarker chartEndCoords = CTMarker.Factory.newInstance();
    chartEndCoords.setCol(column);
    chartEndCoords.setColOff(0);
    chartEndCoords.setRow(row);
    chartEndCoords.setRowOff(0);
    draw.getCTDrawing().getTwoCellAnchorArray(0).setTo(chartEndCoords);
    

    Please refer here for detailed explanation- Resize in POI