カスタム小計ラベルおよび円グラフのその他のラベルに GlobalizationSettings クラスを使用する
Contents
[
Hide
]
考えられる使用シナリオ
Aspose.Cells API がグローバリゼーション設定クラスを使用して、ユーザーがスプレッドシートの小計にカスタム ラベルを使用したいシナリオに対処します。さらに、グローバリゼーション設定クラスを使用して変更することもできます他のワークシートまたはグラフのレンダリング中の円グラフのラベル。
GlobalizationSettings クラスの紹介
のグローバリゼーション設定クラスは現在、カスタム クラスでオーバーライドして、小計の目的のラベルを取得したり、他の円グラフのラベル。
- GlobalizationSettings.GetTotalName: 関数の完全な名前を取得します。
- GlobalizationSettings.GetGrandTotalName: 関数の総計名を取得します。
- GlobalizationSettings.GetOtherName: 円グラフの「その他」ラベルの名前を取得します。
小計のカスタム ラベル
のグローバリゼーション設定クラスをオーバーライドして、小計ラベルをカスタマイズするために使用できます。GlobalizationSettings.GetTotalName & GlobalizationSettings.GetGrandTotalName先に示した方法。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Defines a custom class derived from GlobalizationSettings class | |
class CustomSettings : GlobalizationSettings | |
{ | |
// Overrides the GetTotalName method | |
public override string GetTotalName(ConsolidationFunction functionType) | |
{ | |
// Checks the function type used to add the subtotals | |
switch (functionType) | |
{ | |
// Returns custom value based on the function type used to add the subtotals | |
case ConsolidationFunction.Average: | |
return "AVG"; | |
// Handle other cases as per requirement | |
default: | |
return base.GetTotalName(functionType); | |
} | |
} | |
// Overrides the GetGrandTotalName method | |
public override string GetGrandTotalName(ConsolidationFunction functionType) | |
{ | |
// Checks the function type used to add the subtotals | |
switch (functionType) | |
{ | |
// Returns custom value based on the function type used to add the subtotals | |
case ConsolidationFunction.Average: | |
return "GRD AVG"; | |
// Handle other cases as per requirement | |
default: | |
return base.GetGrandTotalName(functionType); | |
} | |
} | |
} |
カスタム ラベルを挿入するには、WorkbookSettings.GlobalizationSettingsのインスタンスへのプロパティカスタム設定小計をワークシートに追加する前に、上で定義したクラス。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
// 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.Settings.GlobalizationSettings = new CustomSettings(); | |
// Accesses the 1st worksheet from the collection which contains data resides in the cell range A2:B9 | |
Worksheet sheet = book.Worksheets[0]; | |
// Adds Subtotal of type Average to the worksheet | |
sheet.Cells.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 + "output_out.xlsx"); |
のグローバリゼーション設定クラスは、新しい小計を追加する場合にのみ機能します。スプレッドシートにすでに小計が含まれている場合、そのラベルは変更できません。
円グラフの他のラベルのカスタム テキスト
のグローバリゼーション設定クラスオファーGetOtherName円グラフの「その他」ラベルにカスタム値を与えるのに役立つメソッド。次のスニペットは、カスタム クラスを定義し、GetOtherNameシステムのカルチャ識別子に基づいてカスタム ラベルを取得するメソッド。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Defines a custom class inherited by GlobalizationSettings class | |
class GlobalCustomSettings : ChartGlobalizationSettings | |
{ | |
// Overrides the GetOtherName method | |
public override string GetOtherName() | |
{ | |
// Gets the culture identifier for the current system | |
int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID; | |
switch (lcid) | |
{ | |
// Handles case for English | |
case 1033: | |
return "Other"; | |
// Handles case for French | |
case 1036: | |
return "Autre"; | |
// Handles case for German | |
case 1031: | |
return "Andere"; | |
// Handle other cases | |
default: | |
return base.GetOtherName(); | |
} | |
} | |
} |
次のスニペットは、円グラフを含む既存のスプレッドシートを読み込み、グラフを画像にレンダリングします。カスタム設定上記で作成したクラス。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
// 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.Settings.GlobalizationSettings.ChartSettings = new GlobalCustomSettings(); | |
// Accesses the 1st worksheet from the collection which contains pie chart | |
Worksheet sheet = book.Worksheets[0]; | |
// Accesses the 1st chart from the collection | |
Chart chart = sheet.Charts[0]; | |
// Refreshes the chart | |
chart.Calculate(); | |
// Renders the chart to image | |
chart.ToImage(dataDir + "output_out.png", new ImageOrPrintOptions()); |