将图表转换为SVG格式的图像

Contents
[ ]

以下示例代码解释了如何使用Aspose.Cells将图表转换为SVG格式图像。该代码加载源Excel文件,然后将第一个工作表上找到的第一个图表保存为SVG。

下面的截图显示了使用示例代码创建的SVG格式转换图表图像。

输出图像

todo:image_alt_text

由于SVG是基于XML的格式,因此您也可以像在此截图中显示的那样在诸如记事本之类的文本编辑器中打开输出图表图像。

在文本编辑器中的SCG输出

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertCharttoImageinSVGFormat.class);
// Create workbook object from source Excel file
Workbook workbook = new Workbook(dataDir + "sample.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.setImageType(ImageType.SVG);
chart.toImage(dataDir + "ChartImage.svg", options);