تخصيص إعدادات العالمية لجدول محوري
سيناريوهات الاستخدام المحتملة
في بعض الأحيان ترغب في تخصيص إجمالي الجدول المحوري، الإجمالي الفرعي، الإجمالي الكلي، جميع العناصر، العناصر المتعددة، تسميات الأعمدة، تسميات الصفوف، القيم الفارغة نصوص وفقًا لمتطلباتك. تتيح لك Aspose.Cells تخصيص إعدادات العالمية للجدول المحوري للتعامل مع مثل هذه السيناريوات. يمكنك أيضًا استخدام هذه الميزة لتغيير التسميات إلى لغات أخرى مثل العربية والهندية والبولندية، إلخ.
تخصيص إعدادات العالمية لجدول محوري
يشرح الكود المصدر التالي كيفية تخصيص إعدادات العالمية لجدول المحور. ينشئ فئة CustomPivotTableGlobalizationSettings مشتقة من الفئة الأساسية GlobalizationSettings وتعيد جميع الطرق المطلوبة. تعيد هذه الطرق النص المخصص لـ الإجمالي الجدولي، الإجمالي الفرعي، الإجمالي الكلي، جميع العناصر، العناصر المتعددة، تسميات الأعمدة، تسميات الصفوف، القيم الفارغة. ثم يعين كائن هذه الفئة لخاصية WorkbookSettings.GlobalizationSettings. الكود يحمل ملف الإكسل المصدر الذي يحتوي على جدول الدوران ويقوم بتحديث بياناته وحسابها ثم يحفظه كـ ملف PDF الإخراجي. يوضح اللقطة الفوتوغرافية التالية تأثير الكود المصدري على الناتج بتأثير العديد من جزء الجدول المحوري الذي يعود نصه الى الطرق المعدلة للفئة GlobalizationSettings.
الكود المثالي
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
public class CustomizeGlobalizationSettingsforPivotTable { | |
class CustomPivotTableGlobalizationSettings extends GlobalizationSettings | |
{ | |
//Gets the name of "Total" label in the PivotTable. | |
//You need to override this method when the PivotTable contains two or more PivotFields in the data area. | |
public String getPivotTotalName() | |
{ | |
System.out.println("---------GetPivotTotalName-------------"); | |
return "AsposeGetPivotTotalName"; | |
} | |
//Gets the name of "Grand Total" label in the PivotTable. | |
public String getPivotGrandTotalName() | |
{ | |
System.out.println("---------GetPivotGrandTotalName-------------"); | |
return "AsposeGetPivotGrandTotalName"; | |
} | |
//Gets the name of "(Multiple Items)" label in the PivotTable. | |
public String getMultipleItemsName() | |
{ | |
System.out.println("---------GetMultipleItemsName-------------"); | |
return "AsposeGetMultipleItemsName"; | |
} | |
//Gets the name of "(All)" label in the PivotTable. | |
public String getAllName() | |
{ | |
System.out.println("---------GetAllName-------------"); | |
return "AsposeGetAllName"; | |
} | |
//Gets the name of "Column Labels" label in the PivotTable. | |
public String getColumnLabelsOfPivotTable() | |
{ | |
System.out.println("---------GetColumnLabelsOfPivotTable-------------"); | |
return "AsposeGetColumnLabelsOfPivotTable"; | |
} | |
//Gets the name of "Row Labels" label in the PivotTable. | |
public String getRowLabelsNameOfPivotTable() | |
{ | |
System.out.println("---------GetRowLabelsNameOfPivotTable-------------"); | |
return "AsposeGetRowLabelsNameOfPivotTable"; | |
} | |
//Gets the name of "(blank)" label in the PivotTable. | |
public String getEmptyDataName() | |
{ | |
System.out.println("---------GetEmptyDataName-------------"); | |
return "(blank)AsposeGetEmptyDataName"; | |
} | |
//Gets the name of PivotFieldSubtotalType type in the PivotTable. | |
public String getSubTotalName(int subTotalType) | |
{ | |
System.out.println("---------GetSubTotalName-------------"); | |
switch (subTotalType) | |
{ | |
case PivotFieldSubtotalType.SUM: | |
return "AsposeSum";//polish | |
case PivotFieldSubtotalType.COUNT: | |
return "AsposeCount"; | |
case PivotFieldSubtotalType.AVERAGE: | |
return "AsposeAverage"; | |
case PivotFieldSubtotalType.MAX: | |
return "AsposeMax"; | |
case PivotFieldSubtotalType.MIN: | |
return "AsposeMin"; | |
case PivotFieldSubtotalType.PRODUCT: | |
return "AsposeProduct"; | |
case PivotFieldSubtotalType.COUNT_NUMS: | |
return "AsposeCount"; | |
case PivotFieldSubtotalType.STDEV: | |
return "AsposeStdDev"; | |
case PivotFieldSubtotalType.STDEVP: | |
return "AsposeStdDevp"; | |
case PivotFieldSubtotalType.VAR: | |
return "AsposeVar"; | |
case PivotFieldSubtotalType.VARP: | |
return "AsposeVarp"; | |
} | |
return "AsposeSubTotalName"; | |
} | |
} | |
public void RunCustomizeGlobalizationSettingsforPivotTable() throws Exception | |
{ | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CustomizeGlobalizationSettingsforPivotTable.class) + "PivotTables/"; | |
//Load your excel file | |
Workbook wb = new Workbook(dataDir + "samplePivotTableGlobalizationSettings.xlsx"); | |
//Setting Custom Pivot Table Globalization Settings | |
wb.getSettings().setGlobalizationSettings(new CustomPivotTableGlobalizationSettings()); | |
//Hide first worksheet that contains the data of the pivot table | |
wb.getWorksheets().get(0).setVisible(false); | |
//Access second worksheet | |
Worksheet ws = wb.getWorksheets().get(1); | |
//Access the pivot table, refresh and calculate its data | |
PivotTable pt = ws.getPivotTables().get(0); | |
pt.setRefreshDataFlag(true); | |
pt.refreshData(); | |
pt.calculateData(); | |
pt.setRefreshDataFlag(false); | |
//Pdf save options - save entire worksheet on a single pdf page | |
PdfSaveOptions options = new PdfSaveOptions(); | |
options.setOnePagePerSheet(true); | |
//Save the output pdf | |
wb.save(dataDir + "outputPivotTableGlobalizationSettings.pdf", options); | |
} | |
public static void main(String[] args) throws Exception { | |
CustomizeGlobalizationSettingsforPivotTable pg = new CustomizeGlobalizationSettingsforPivotTable(); | |
pg.RunCustomizeGlobalizationSettingsforPivotTable(); | |
} |