Skip to content

Instantly share code, notes, and snippets.

@conholdate-gists
Last active January 11, 2022 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conholdate-gists/aca03417d1b648fb7da34bc1fbe07783 to your computer and use it in GitHub Desktop.
Save conholdate-gists/aca03417d1b648fb7da34bc1fbe07783 to your computer and use it in GitHub Desktop.
Convert Excel Charts to SVG using Java
// This code example demonstrates how to convert chart from Excel to SVG
// Load Excel file in workbook object
Workbook workbook = new Workbook("C:\\Files\\Cells\\Sample_Chart.xlsx");
// Access the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Access the first chart inside the worksheet
Chart chart = worksheet.getCharts().get(0);
// Save the chart into image in SVG format
ImageOrPrintOptions options = new ImageOrPrintOptions();
options.setSaveFormat(SaveFormat.SVG);
chart.toImage("C:\\Files\\Cells\\Sample_Chart_out.svg", options);
// This code example demonstrates how to convert chart from Excel to SVG and set it to fit in viewport
// Load Excel file in workbook object
Workbook workbook = new Workbook("C:\\Files\\Cells\\Sample_Chart.xlsx");
// Access the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Access the first chart inside the worksheet
Chart chart = worksheet.getCharts().get(0);
// Set image or print options
// with SVGFitToViewPort true
ImageOrPrintOptions options = new ImageOrPrintOptions();
options.setSaveFormat(SaveFormat.SVG);
options.setSVGFitToViewPort(true);
chart.toImage("C:\\Files\\Cells\\Sample_Chart_ViewPort_out.svg", options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment