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

Contents
[ ]

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

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

输出图像

待办事项:图片_替代_文本

因为 SVG 是一种基于 XML 的格式,您还可以在记事本等文本编辑器中打开输出图表图像,如该屏幕截图所示。

在文本编辑器中输出 SCG

待办事项:图片_替代_文本

// 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);