استخدام فئة GlobalizationSettings لتخصيص علامات مجموع جزئي مخصصة وعلامة أخرى لمخطط البيت

سيناريوهات الاستخدام المحتملة

فقد قامت واجهات برمجة التطبيقات Aspose.Cells بتعريض فئة GlobalizationSettings للتعامل مع السيناريوهات التي يرغب المستخدم في استخدام تسميات مخصصة للمجموعات الفرعية في ورق العمل. بالإضافة إلى ذلك، يمكن استخدام فئة GlobalizationSettings أيضًا لتعديل تسمية أخرى لرسم الدائري أثناء عرض ورقة العمل أو الرسم البياني.

مقدمة في فئة GlobalizationSettings

تقدم فئة GlobalizationSettings حاليًا 3 طرق يمكن تجاوزها في فئة مخصصة للحصول على تسميات المجموعات الفرعية المرغوبة أو لعرض نص مخصص لتسمية أخرى لرسم الدائري.

  1. GlobalizationSettings.getTotalName: يحصل على اسم الإجمالي للدالة.
  2. GlobalizationSettings.getGrandTotalName: يحصل على اسم الإجمالي العام للدالة.
  3. GlobalizationSettings.getOtherName: يحصل على اسم تسميات “أخرى” لرسوم بيانية دائريّة.

علامات مخصصة للمجاميع الجزئية

يمكن استخدام فئة GlobalizationSettings لتخصيص تسميات المجموع الفرعي عن طريق تجاوز الطرق 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 إلى نسخة من فئة CustomSettings المعرفة أعلاه قبل إضافة المجاميع الفرعية إلى ورقة العمل.

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

نص مخصص لعلامة “أخرى” لمخطط البيت

يقدم GlobalizationSettings طريقة 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();
}
}

تحميل الرقم الجدول الموجود يحتوي على شريحة ويقوم بإظهار الشريحة لصورة أثناء استخدام فئة CustomSettings التي تم إنشاؤها سابقًا.

// 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” كما هو محدد في فئة CustomSettings.

todo:image_alt_text