تنسيق الجدول المحوري
مظهر الجدول المحوري
كيفية إنشاء جدول محوري أظهر كيفية إنشاء جدول محوري بسيط. تذهب هذه المقالة إلى أبعد من ذلك وتناقش كيفية تخصيص مظهر الجدول المحوري عن طريق تعيين الخصائص.
تعيين خيارات تنسيق الجدول المحوري
الجدول محوري تتيح لك class تعيين خيارات تنسيق متنوعة لجدول محوري.
تعيين التنسيق التلقائي وأنواع PivotTableStyle
يوضح مثال الرمز التالي كيفية تعيين نوع التنسيق التلقائي ونوع نمط الجدول المحوري باستخدام ملفنوع التنسيق التلقائي وPivotTableStyleType الخصائص.
// 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(SetAutoFormatandPivotTableStyleTypes.class) + "PivotTables/"; | |
// Load a template file | |
Workbook workbook = new Workbook(dataDir + "PivotTable.xls"); | |
int pivotindex = 0; | |
// Get the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(pivotindex); | |
// Accessing the PivotTable | |
PivotTable pivotTable = worksheet.getPivotTables().get(pivotindex); | |
//Setting the PivotTable report is automatically formatted for Excel 2003 formats | |
pivotTable.setAutoFormat(true); | |
//Setting the PivotTable atuoformat type. | |
pivotTable.setAutoFormatType(PivotTableAutoFormatType.CLASSIC); | |
//Setting the PivotTable's Styles for Excel 2007/2010 formats e.g XLSX. | |
pivotTable.setPivotTableStyleType(PivotTableStyleType.PIVOT_TABLE_STYLE_LIGHT_1); |
ضبط خيارات التنسيق
يوضح نموذج التعليمات البرمجية التالي كيفية تعيين عدد من خيارات التنسيق لتقرير الجدول المحوري ، بما في ذلك إضافة الإجماليات الكلية للصفوف والأعمدة.
// 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(SettingFormatOptions.class) + "PivotTables/"; | |
// Load a template file | |
Workbook workbook = new Workbook(dataDir + "PivotTable.xls"); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
PivotTable pivotTable = worksheet.getPivotTables().get(0); | |
// Dragging the third field to the data area. | |
pivotTable.addFieldToArea(PivotFieldType.DATA, 2); | |
// Show grand totals for rows. | |
pivotTable.setRowGrand(true); | |
// Show grand totals for columns. | |
pivotTable.setColumnGrand(true); | |
// Display a custom string in cells that contain null values. | |
pivotTable.setDisplayNullString(true); | |
pivotTable.setNullString("null"); | |
// Setting the layout | |
pivotTable.setPageFieldOrder(PrintOrderType.DOWN_THEN_OVER); |
تعيين خيارات تنسيق PivotFields
بالإضافة إلى التحكم في تنسيق الجدول المحوري الكلي ، يسمح Aspose.Cells for Java بالتحكم الدقيق في تنسيق حقول الصفوف وحقول الأعمدة وحقول الصفحة.
تعيين تنسيق حقول الصف والعمود والصفحة
يوضح مثال الكود التالي كيفية الوصول إلى حقول الصف ، والوصول إلى صف معين ، وتعيين الإجماليات الفرعية ، وتطبيق الفرز التلقائي ، واستخدام خيار AutoShow.
// 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(SetRowColumnPageFieldsFormat.class) + "PivotTables/"; | |
// Load a template file | |
Workbook workbook = new Workbook(dataDir + "PivotTable.xls"); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
PivotTable pivotTable = worksheet.getPivotTables().get(0); | |
// Accessing the row fields. | |
PivotFieldCollection pivotFields = pivotTable.getRowFields(); | |
// Accessing the first row field in the row fields. | |
PivotField pivotField = pivotFields.get(0); | |
// Setting Subtotals. | |
pivotField.setSubtotals(PivotFieldSubtotalType.SUM, true); | |
pivotField.setSubtotals(PivotFieldSubtotalType.COUNT, true); | |
// Setting autosort options. Setting the field auto sort. | |
pivotField.setAutoSort(true); | |
// Setting the field auto sort ascend. | |
pivotField.setAscendSort(true); | |
// Setting the field auto sort using the field itself. | |
pivotField.setAutoSortField(-1); | |
// Setting autoShow options. Setting the field auto show. | |
pivotField.setAutoShow(true); | |
// Setting the field auto show ascend. | |
pivotField.setAscendShow(false); | |
// Setting the auto show using field(data field). | |
pivotField.setAutoShowField(0); |
ضبط تنسيق حقول البيانات
توضح سطور التعليمات البرمجية التالية كيفية تنسيق حقول البيانات.
// 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(SettingDataFieldFormat.class) + "PivotTables/"; | |
// Load a template file | |
Workbook workbook = new Workbook(dataDir + "PivotTable.xls"); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
PivotTable pivotTable = worksheet.getPivotTables().get(0); | |
// Accessing the data fields. | |
PivotFieldCollection pivotFields = pivotTable.getDataFields(); | |
// Accessing the first data field in the data fields. | |
PivotField pivotField = pivotFields.get(0); | |
// Setting data display format | |
pivotField.setDataDisplayFormat(PivotFieldDataDisplayFormat.PERCENTAGE_OF); | |
// Setting the base field. | |
pivotField.setBaseFieldIndex(1); | |
// Setting the base item. | |
pivotField.setBaseItemPosition(PivotItemPosition.NEXT); | |
// Setting number format | |
pivotField.setNumber(10); |
تعديل النمط السريع للجدول المحوري
توضح أمثلة التعليمات البرمجية التالية كيفية تعديل النمط السريع المطبق على الجدول المحوري.
// 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(ModifyPivotTableQuickStyle.class) + "PivotTables/"; | |
// Open the template file containing the pivot table. | |
Workbook wb = new Workbook(dataDir + "sample1.xlsx"); | |
// Add Pivot Table style | |
Style style1 = wb.createStyle(); | |
com.aspose.cells.Font font1 = style1.getFont(); | |
font1.setColor(Color.getRed()); | |
Style style2 = wb.createStyle(); | |
com.aspose.cells.Font font2 = style2.getFont(); | |
font2.setColor(Color.getBlue()); | |
int i = wb.getWorksheets().getTableStyles().addPivotTableStyle("tt"); | |
// Get and Set the table style for different categories | |
TableStyle ts = wb.getWorksheets().getTableStyles().get(i); | |
int index = ts.getTableStyleElements().add(TableStyleElementType.FIRST_COLUMN); | |
TableStyleElement e = ts.getTableStyleElements().get(index); | |
e.setElementStyle(style1); | |
index = ts.getTableStyleElements().add(TableStyleElementType.GRAND_TOTAL_ROW); | |
e = ts.getTableStyleElements().get(index); | |
e.setElementStyle(style2); | |
// Set Pivot Table style name | |
PivotTable pt = wb.getWorksheets().get(0).getPivotTables().get(0); | |
pt.setPivotTableStyleName("tt"); | |
// Save the file. | |
wb.save(dataDir + "ModifyPivotTableQuickStyle_out.xlsx"); |
مسح الحقول المحورية
مجموعة PivotFieldCollection طريقة اسمه[صافي()](https://reference.aspose.com/cells/java/com.aspose.cells/pivotfieldcollection#clear()يمسح الحقول المحورية. استخدمه لمسح الحقول المحورية في جميع المناطق على سبيل المثال ، الصفحة أو العمود أو الصف أو البيانات. يوضح نموذج التعليمات البرمجية أدناه كيفية مسح كافة الحقول المحورية في منطقة البيانات.
// 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(ClearPivotFields.class) + "PivotTables/"; | |
// Load a template file | |
Workbook workbook = new Workbook(dataDir + "PivotTable.xls"); | |
// Get the first worksheet | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Get the pivot tables in the sheet | |
PivotTableCollection pivotTables = sheet.getPivotTables(); | |
// Get the first PivotTable | |
PivotTable pivotTable = pivotTables.get(0); | |
// Clear all the data fields | |
pivotTable.getDataFields().clear(); | |
// Add new data field | |
pivotTable.addFieldToArea(PivotFieldType.DATA, "Betrag Netto FW"); | |
// Set the refresh data flag on | |
pivotTable.setRefreshDataFlag(false); | |
// Refresh and calculate the pivot table data | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
// Save the Excel file | |
workbook.save(dataDir + "ClearPivotFields_out.xlsx"); |
وظيفة التوحيد
تطبيق ConsolidationFunction على حقول البيانات في Pivot Table
يمكن استخدام Aspose.Cells لتطبيق ConsolidationFunction على حقول البيانات (أو حقول القيمة) للجدول المحوري. في Microsoft Excel ، يمكنك النقر بزر الماوس الأيمن فوق حقل القيمة ثم تحديدإعدادات حقل القيمة … الخيار ثم حدد علامة التبويبتلخيص القيم حسب. من هناك ، يمكنك تحديد أي دالة توحيد من اختيارك مثل المجموع ، العدد ، المتوسط ، الحد الأقصى ، الحد الأدنى ، المنتج ، العدد المميز وما إلى ذلك.
يوفر Aspose.Cellsالتوحيد التعداد لدعم وظائف التوحيد التالية.
- ConsolidationFunction.AVERAGE
- التوحيد وظيفة. العد
- التوحيد. COUNT_NUMS
- عملية التوحيد. DISTINCT_COUNT
- التوحيد
- التوحيد
- التوحيد. المنتج
- التوحيد. STD_DEV
- التوحيد. STD_DEVP
- التوحيد SUM
- التوحيد. VAR
- التوحيد. VARP
الكود التالي ينطبقمتوسط وظيفة التوحيد إلى حقل البيانات الأول (أو حقل القيمة) ومتميز وظيفة التوحيد في حقل البيانات الثاني (أو حقل القيمة).
// 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(ConsolidationFunctions.class) + "PivotTables/"; | |
// Create workbook from source excel file | |
Workbook workbook = new Workbook(dataDir + "sample1.xlsx"); | |
// Access the first worksheet of the workbook | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access the first pivot table of the worksheet | |
PivotTable pivotTable = worksheet.getPivotTables().get(0); | |
// Apply Average consolidation function to first data field | |
pivotTable.getDataFields().get(0).setFunction(ConsolidationFunction.AVERAGE); | |
// Apply DistinctCount consolidation function to second data field | |
pivotTable.getDataFields().get(1).setFunction(ConsolidationFunction.DISTINCT_COUNT); | |
// Calculate the data to make changes affect | |
pivotTable.calculateData(); | |
// Save the workbook | |
workbook.save(dataDir + "ConsolidationFunctions_out.xlsx"); |