以其他语言实施小计或总计标签

可能的使用场景

有时,您想用非英语语言(如中文、日语、阿拉伯语、印地语等)显示小计和总计标签。Aspose.Cells 允许您使用全球化设置类和工作簿.全球化设置财产。请参阅这篇文章了解如何使用全球化设置班级

以其他语言实施小计或总计标签

下面的示例代码加载示例 excel 文件并以中文实现小计和总计名称。请检查输出Excel文件此代码生成供您参考。我们首先创建一个类全球化设置然后在我们的代码中使用它。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
class GlobalizationSettingsImp : GlobalizationSettings
{
// This function will return the sub total name
public override String GetTotalName(ConsolidationFunction functionType)
{
return "Chinese Total - 可能的用法";
}
// This function will return the grand total name
public override String GetGrandTotalName(ConsolidationFunction functionType)
{
return "Chinese Grand Total - 可能的用法";
}
}

现在在代码中使用上面创建的类,如下所示:

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Load your source workbook
Workbook wb = new Workbook(dataDir + "sample.xlsx");
// Set the glorbalization setting to change subtotal and grand total names
GlobalizationSettings gsi = new GlobalizationSettingsImp();
wb.Settings.GlobalizationSettings = gsi;
// Access first worksheet
Worksheet ws = wb.Worksheets[0];
// Apply subtotal on A1:B10
CellArea ca = CellArea.CreateCellArea("A1", "B10");
ws.Cells.Subtotal(ca, 0, ConsolidationFunction.Sum, new int[] { 2, 3, 4 });
// Set the width of the first column
ws.Cells.SetColumnWidth(0, 40);
// Save the output excel file
wb.Save(dataDir + "output_out.xlsx");