将图表转换为 SVG 格式的图像
Contents
[
Hide
]
Scalable Vector Graphics (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); |