Özel Alt Toplam Etiketleri ve Pasta Grafiği Diğer Etiketleri İçin GlobalizationSettings Sınıfını Kullanma
Olası Kullanım Senaryoları
Aspose.Cells API’leri, kullanıcının elektronik tabloda Özel Alt Toplam etiketleri kullanmak istediği senaryolarla başa çıkmak için GlobalizationSettings sınıfını açığa çıkarmıştır. Ayrıca, GlobalizationSettings sınıfı, çalışma sayfasını veya çizimi render ederken Diğer etiketi için özel metni değiştirmek için kullanılabilir.
GlobalizationSettings Sınıfı Tanıtımı
GlobalizationSettings sınıfı şu anda istenen toplam etiketleri almak için özelleştirilmiş bir sınıfta geçersiz kılınabilen aşağıdaki 3 yöntemi sunmaktadır veya bir Pasta grafiğinin Diğer etiketi için özel metni oluşturmak için.
- GlobalizationSettings.GetTotalName: Fonksiyonun toplam ismini alır.
- GlobalizationSettings.GetGrandTotalName: Fonksiyonun genel toplam ismini alır.
- GlobalizationSettings.GetOtherName: Pie grafikleri için “Diğer” etiketlerin adını alır.
Alt toplamlar için özel etiketler
GlobalizationSettings sınıfı, alt toplam etiketlerini özelleştirmek için önümüzdeki gibi GlobalizationSettings.GetTotalName ve GlobalizationSettings.GetGrandTotalName yöntemlerini geçersiz kılma amacıyla kullanılabilir.
// 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); | |
} | |
} | |
} |
Özel etiketler enjekte etmek için, Alt toplamları çalışma sayfasına eklemek öncesinde yukarıda tanımlanan CustomSettings sınıfına bir örnek atamak gereklidir.
// 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"); |
Pasta Grafiği için Diğer Etiket için Özel Metin
GlobalizationSettings sınıfı, Pasta grafiklerinin “Diğer” etiketine özel bir değer vermek için yararlı olan GetOtherName yöntemi sunar. Aşağıdaki kesit, bir özel sınıfı tanımlar ve sistem kültür tanımlayıcısına dayalı bir özel etiket almak için GetOtherName yöntemini geçersiz kılar.
// 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(); | |
} | |
} | |
} |
Aşağıdaki kesit, yukarıda oluşturulan CustomSettings sınıfını kullanarak bir Pasta grafiği içeren mevcut bir elektronik tabloyu yükler ve grafiği resim olarak oluşturur.
// 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()); |