设置图表系列的值格式代码
Contents
[
Hide
]
可能的使用场景
您可以使用Series.ValuesFormatCode属性设置图表系列的值格式代码。此属性不仅对基于工作表内范围的系列有用,还可用于基于数值数组创建的系列。
设置图表系列的值格式代码
以下示例代码在空图表中添加了一个系列,该图表之前没有系列。它使用数值数组添加了系列。添加系列后,它使用$#,##0代码进行格式化,使用Series.ValuesFormatCode属性,数字10000变成$10,000。屏幕截图显示了代码在执行后对sample Excel file和output Excel file的影响。
示例代码
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 | |
//Load the source Excel file | |
Workbook wb = new Workbook("51740712.xlsx"); | |
//Access first worksheet | |
Worksheet worksheet = wb.Worksheets[0]; | |
//Access first chart | |
Chart ch = worksheet.Charts[0]; | |
//Add series using an array of values | |
ch.NSeries.Add("{10000, 20000, 30000, 40000}", true); | |
//Access the series and set its values format code | |
Series srs = ch.NSeries[0]; | |
srs.ValuesFormatCode = "$#,##0"; | |
//Save the output Excel file | |
wb.Save("51740713.xlsx"); |