カスタム小計ラベルおよび円グラフのその他のラベルに GlobalizationSettings クラスを使用する

考えられる使用シナリオ

Aspose.Cells API がグローバリゼーション設定クラスを使用して、ユーザーがスプレッドシートの小計にカスタム ラベルを使用したいシナリオに対処します。さらに、グローバリゼーション設定クラスを使用して変更することもできます他のワークシートまたはグラフのレンダリング中の円グラフのラベル。

GlobalizationSettings クラスの紹介

グローバリゼーション設定クラスは現在、カスタム クラスでオーバーライドして、小計の目的のラベルを取得したり、他の円グラフのラベル。

  1. GlobalizationSettings.getTotalName: 関数の完全な名前を取得します。
  2. GlobalizationSettings.getGrandTotalName: 関数の総計名を取得します。
  3. GlobalizationSettings.getOtherName: 円グラフの「その他」ラベルの名前を取得します。

小計のカスタム ラベル

グローバリゼーション設定クラスをオーバーライドして、小計ラベルをカスタマイズするために使用できます。GlobalizationSettings.getTotalName & GlobalizationSettings.getGrandTotalName メソッドは先に示したとおりです。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
public String getTotalName(int functionType) {
switch (functionType) {
case ConsolidationFunction.AVERAGE:
return "AVG";
// Handle other cases
default:
return super.getTotalName(functionType);
}
}
public String getGrandTotalName(int functionType) {
switch (functionType) {
case ConsolidationFunction.AVERAGE:
return "GRAND AVG";
// Handle other cases
default:
return super.getGrandTotalName(functionType);
}
}
public String getOtherName()
{
String language = Locale.getDefault().getLanguage();
System.out.println(language);
switch (language)
{
case "en":
return "Other";
case "fr":
return "Autre";
case "de":
return "Andere";
//Handle other cases as per requirement
default:
return super.getOtherName();
}
}

カスタム ラベルを挿入するには、WorkbookSettings.GlobalizationSettingsのインスタンスへのプロパティカスタム設定小計をワークシートに追加する前に、上で定義したクラス。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(CustomLabelsforSubtotals.class) + "articles/";
// Loads an existing spreadsheet containing some data
Workbook book = new Workbook(dataDir + "sample.xlsx");
// Assigns the GlobalizationSettings property of the WorkbookSettings
// class
// to the class created in first step
book.getSettings().setGlobalizationSettings(new CustomSettings());
// Accesses the 1st worksheet from the collection which contains data
// Data resides in the cell range A2:B9
Worksheet sheet = book.getWorksheets().get(0);
// Adds SubTotal of type Average to the worksheet
sheet.getCells().subtotal(CellArea.createCellArea("A2", "B9"), 0, ConsolidationFunction.AVERAGE, new int[] { 1 });
// Calculates Formulas
book.calculateFormula();
// Auto fits all columns
sheet.autoFitColumns();
// Saves the workbook on disc
book.save(dataDir + "CustomLabelsforSubtotals_out.xlsx");

円グラフの他のラベルのカスタム テキスト

グローバリゼーション設定クラスが提供するgetOtherName 円グラフの「その他」ラベルにカスタム値を与えるのに役立つメソッド。次のスニペットは、カスタム クラスを定義し、getOtherName メソッドを使用して、JVM のデフォルト言語セットに基づいてカスタム ラベルを取得します。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
public String getTotalName(int functionType) {
switch (functionType) {
case ConsolidationFunction.AVERAGE:
return "AVG";
// Handle other cases
default:
return super.getTotalName(functionType);
}
}
public String getGrandTotalName(int functionType) {
switch (functionType) {
case ConsolidationFunction.AVERAGE:
return "GRAND AVG";
// Handle other cases
default:
return super.getGrandTotalName(functionType);
}
}
public String getOtherName()
{
String language = Locale.getDefault().getLanguage();
System.out.println(language);
switch (language)
{
case "en":
return "Other";
case "fr":
return "Autre";
case "de":
return "Andere";
//Handle other cases as per requirement
default:
return super.getOtherName();
}
}

次のスニペットは、円グラフを含む既存のスプレッドシートを読み込み、グラフを画像にレンダリングします。カスタム設定上記で作成したクラス。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(CustomTextforOtherLabelofPieChart.class) + "articles/";
//Loads an existing spreadsheet containing a pie chart
Workbook book = new Workbook(dataDir + "sample.xlsx");
//Assigns the GlobalizationSettings property of the WorkbookSettings class
//to the class created in first step
book.getSettings().setGlobalizationSettings(new CustomSettings());
//Accesses the 1st worksheet from the collection which contains pie chart
Worksheet sheet = book.getWorksheets().get(0);
//Accesses the 1st chart from the collection
Chart chart = sheet.getCharts().get(0);
//Refreshes the chart
chart.calculate();
//Renders the chart to image
chart.toImage(dataDir + "CustomTextforOtherLabelofPieChart_out.png", new ImageOrPrintOptions());

以下は、マシンのロケールがフランスに設定されている場合の結果のイメージです。で定義されているように、ラベル「Other」が「Autre」に変換されていることがわかります。カスタム設定クラス。

todo:画像_代替_文章