设置图表系列的值格式代码
Contents
[
Hide
]
可能的使用场景
您可以使用设置图表系列的值格式代码系列.ValuesFormatCode财产。此属性不仅适用于基于工作表内范围的系列,而且适用于使用值数组创建的系列。
设置图表系列的值格式代码
以下示例代码在之前没有系列的空图表中添加一个系列。它使用值数组添加系列。一次,它添加系列,使用代码 $#,##0 格式化它系列.ValuesFormatCode财产,数字 10000 变为 $10,000。截图展示了代码对示例 Excel 文件和输出Excel文件执行后。
示例代码
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 | |
//Load the source Excel file | |
Workbook wb = new Workbook("sampleSeries_ValuesFormatCode.xlsx"); | |
//Access first worksheet | |
Worksheet worksheet = wb.getWorksheets().get(0); | |
//Access first chart | |
Chart ch = worksheet.getCharts().get(0); | |
//Add series using an array of values | |
ch.getNSeries().add("{10000, 20000, 30000, 40000}", true); | |
//Access the series and set its values format code | |
Series srs = ch.getNSeries().get(0); | |
srs.setValuesFormatCode("$#,##0"); | |
//Save the output Excel file | |
wb.save("outputSeries_ValuesFormatCode.xlsx"); |