导出带有viewBox属性的SVG图表
Contents
[
Hide
]
默认情况下,将图表导出为SVG格式时,其XML中不包括viewBox属性。但是,Aspose.Cells提供了一个属性,当设置为true时,将图表导出为带有viewBox属性的SVG。
如果在记事本中打开图表的SVG文件,将会找到类似于这样的viewBox属性。
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="100%" height="100%"
viewBox="0 0 480 288">
代码片段
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ExportCharttoSVG.class); | |
// Create workbook object from source file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access first chart inside the worksheet | |
Chart chart = worksheet.getCharts().get(0); | |
// Set image or print options | |
// with SVGFitToViewPort true | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.setSaveFormat(SaveFormat.SVG); | |
opts.setSVGFitToViewPort(true); | |
// Save the chart to svg format | |
chart.toImage(dataDir + "out.svg", opts); | |