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