用 Node.js 通过 C++ 实现其他语言的 Subtotal 或 Grand Total 标签
Contents
[
Hide
]
可能的使用场景
有时,你希望用非英文语言如中文、日语、阿拉伯语、印地语等显示 subtotal 和 grand total 标签。Aspose.Cells for Node.js via C++ 允许你通过 GlobalizationSettings 类和 GlobalizationSettings 属性实现。请参阅关于如何使用 GlobalizationSettings 类的相关文章。
用其他语言实现子合计或总计标签
以下示例代码加载示例 Excel 文件,并用中文实现了 subtotal 和 grand total 的名称。请检查由此代码生成的输出 Excel 文件,以供参考。我们首先创建 GlobalizationSettings 类的实例,然后在代码中使用它。
const AsposeCells = require("aspose.cells.node");
class GlobalizationSettingsImp extends AsposeCells.GlobalizationSettings {
// This function will return the sub total name
getTotalName(functionType) {
return "Chinese Total - 可能的用法";
}
// This function will return the grand total name
getGrandTotalName(functionType) {
return "Chinese Grand Total - 可能的用法";
}
}
现在在代码中使用上述创建的类如下:
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Load your source workbook
const workbook = new AsposeCells.Workbook(path.join(dataDir, "sample.xlsx"));
// Set the globalization setting to change subtotal and grand total names
const globalizationSettings = new AsposeCells.GlobalizationSettings();
workbook.getSettings().setGlobalizationSettings(globalizationSettings);
// Access first worksheet
const worksheet = workbook.getWorksheets().get(0);
// Apply subtotal on A1:B10
const cellArea = AsposeCells.CellArea.createCellArea("A1", "B10");
worksheet.getCells().subtotal(cellArea, 0, AsposeCells.ConsolidationFunction.Sum, [2, 3, 4]);
// Set the width of the first column
worksheet.getCells().setColumnWidth(0, 40);
// Save the output excel file
workbook.save(path.join(dataDir, "output_out.xlsx"));