Implement Subtotal or Grand Total Labels in Other Languages with Node.js via C++

Possible Usage Scenarios

Sometimes, you want to show subtotal and grand total labels in non‑English languages such as Chinese, Japanese, Arabic, Hindi, etc. Aspose.Cells for Node.js via C++ allows you to do this using the GlobalizationSettings class and its property. Please see this article on how to use the GlobalizationSettings class.

Implement Subtotal or Grand Total Labels in Other Languages

The following sample code loads the sample Excel file and implements subtotal and grand total names in the Chinese language. Please check the output Excel file generated by this code for your reference. We first create a class that extends GlobalizationSettings and then use it in our code.

const AsposeCells = require("aspose.cells.node");

class GlobalizationSettingsImp extends AsposeCells.GlobalizationSettings {
    // This function will return the subtotal name
    getTotalName(functionType) {
        return "Chinese Total - 可能的用法";
    }

    // This function will return the grand total name
    getGrandTotalName(functionType) {
        return "Chinese Grand Total - 可能的用法";
    }
}

Now use the class created above in the code as follows:

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 the 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"));