用Node.js通过C++设置图表系列的数值格式代码
Contents
[
Hide
]
可能的使用场景
你可以使用Series.getValuesFormatCode()属性设置图表系列的数值格式代码。此属性不仅适用于基于工作表范围的系列,也适用于使用值数组创建的系列。
设置图表系列的值格式代码
以下示例代码在空的无系列图表中添加一个系列,使用数组值添加系列。添加后,使用Series.getValuesFormatCode()属性将其格式化为$#,##0,数字10000变成$10,000。截图显示执行后对示例Excel文件(51740712.xlsx)和输出Excel文件(51740713.xlsx)的效果。
示例代码
const AsposeCells = require("aspose.cells.node");
const path = require("path");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "51740712.xlsx");
// Load the source Excel file
const workbook = new AsposeCells.Workbook(filePath);
// Access first worksheet
const worksheet = workbook.getWorksheets().get(0);
// Access first chart
const chart = worksheet.getCharts().get(0);
// Add series using an array of values
chart.getNSeries().add("{10000, 20000, 30000, 40000}", true);
// Access the series and set its values format code
const series = chart.getNSeries().get(0);
series.setValuesFormatCode("$#,##0");
// Save the output Excel file
workbook.save(path.join(dataDir, "51740713.xlsx"));