استخدام فئة GlobalizationSettings لتخصيص علامات مجموع جزئي مخصصة وعلامة أخرى لمخطط البيت
سيناريوهات الاستخدام المحتملة
فقد قامت واجهات برمجة التطبيقات Aspose.Cells بتعريض فئة GlobalizationSettings للتعامل مع السيناريوهات التي يرغب المستخدم في استخدام تسميات مخصصة للمجموعات الفرعية في ورق العمل. بالإضافة إلى ذلك، يمكن استخدام فئة GlobalizationSettings أيضًا لتعديل تسمية أخرى لرسم الدائري أثناء عرض ورقة العمل أو الرسم البياني.
مقدمة في فئة GlobalizationSettings
تقدم فئة GlobalizationSettings حاليًا 3 طرق يمكن تجاوزها في فئة مخصصة للحصول على تسميات المجموعات الفرعية المرغوبة أو لعرض نص مخصص لتسمية أخرى لرسم الدائري.
- GlobalizationSettings.getTotalName: يحصل على اسم المجموع للوظيفة.
- GlobalizationSettings.getGrandTotalName: يحصل على اسم الإجمالي الكبير للوظيفة.
- 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 التي تُفيد في إعطاء قيمة مخصصة لرقمية “Other” بشكل دوري. الشريحة التالية تحدد فئة مخصصة وتعدل الطريقة 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.