将图表转换为SVG格式的图像
Contents
[
Hide
]
可缩放矢量图形(SVG)是一种基于XML的二维图形格式,还支持交互和动画。SVG规范是由万维网联盟(W3C)自1999年以来制定的开放标准。
SVG图像及其行为是在XML文本文件中定义的。这意味着它们可以被搜索、索引、编写脚本和压缩。作为XML文件,SVG图像可以使用任何文本编辑器创建和编辑,但更常见的是使用绘图软件创建。
Aspose.Cells可以将图表保存为BMP、JPEG、PNG、GIF、SVG等多种格式的图像。本文解释了如何将图表保存为SVG格式。
以下示例代码解释了如何使用Aspose.Cells将图表转换为SVG格式图像。该代码加载源Microsoft Excel文件,然后将第一个工作表上找到的第一个图表保存为SVG。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source file | |
Workbook workbook = new Workbook(dataDir + "SampleChartBook.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access first chart inside the worksheet | |
Aspose.Cells.Charts.Chart chart = worksheet.Charts[0]; | |
// Set image or print options | |
Aspose.Cells.Rendering.ImageOrPrintOptions opts = new Aspose.Cells.Rendering.ImageOrPrintOptions(); | |
opts.ImageType = ImageType.Svg; | |
// Save the chart to svg format | |
chart.ToImage(dataDir + "Image_out.svg", opts); |