تنسيق جدول الدوران
مظهر جدول الدوران
كيفية إنشاء جدول دوران يشرح كيفية إنشاء جدول دوران بسيط. يوضح هذا المقال كيفية تخصيص مظهر جدول الدوران عن طريق تعيين مختلف الخصائص:
- خيارات تنسيق جدول الدوران
- خيارات تنسيق حقول الجدول الدوران
- خيارات تنسيق حقل البيانات
كيفية تعيين خيارات تنسيق جدول البيانات المحورية
تتحكم فئة PivotTable في الجدول الدوري الكلي ويمكن تهيئتها بعدة طرق.
كيفية تعيين نوع التنسيق التلقائي
يقدم Microsoft Excel عددًا من تنسيقات التقارير المسبقة. يدعم Aspose.Cells for Node.js via C++ أيضًا هذه الخيارات التنسيقية. للوصول إليها:
- قم بتعيين PivotTable.setIsAutoFormat(value) إلى صحيح.
- قم بتعيين خيار التنسيق من تعداد PivotTableAutoFormatType .
const AsposeCells = require("aspose.cells.node"); | |
//For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
//The path to the documents directory. | |
var dataDir = RunExamples.GetDataDir("."); | |
//Load a template file | |
var workbook = new AsposeCells.Workbook(dataDir + "Book1.xls"); | |
var pivotindex = 0; | |
//Get the first worksheet | |
var worksheet = workbook.getWorksheets().get(0); | |
//Accessing the PivotTable | |
var pivotTable = worksheet.getPivotTables().get(pivotindex); | |
//Setting the PivotTable report is automatically formatted | |
pivotTable.setIsAutoFormat(true); | |
//Setting the PivotTable atuoformat type. | |
pivotTable.setAutoFormatType(AsposeCells.PivotTableAutoFormatType.Report5); | |
//Saving the Excel file | |
workbook.save(dataDir + "output.xls"); |
كيفية تعيين خيارات التنسيق
تُظهر العينة البرمجية أدناه كيفية تنسيق جدول الدوري لإظهار المجاميع الكلية للصفوف والأعمدة، وكيفية تعيين ترتيب حقل التقرير. كما تُظهر العينة أيضًا كيفية تعيين سلسلة مخصصة لقيم خالية.
const AsposeCells = require("aspose.cells.node"); | |
//For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
//The path to the documents directory. | |
var dataDir = RunExamples.GetDataDir("."); | |
//Load a template file | |
var workbook = new AsposeCells.Workbook(dataDir + "Book1.xls"); | |
//Get the first worksheet | |
var worksheet = workbook.getWorksheets().get(0); | |
var pivotindex = 0; | |
//Accessing the PivotTable | |
var pivotTable = worksheet.getPivotTables().get(pivotindex); | |
//Setting the PivotTable report shows grand totals for rows. | |
pivotTable.setRowGrand(true); | |
//Setting the PivotTable report shows grand totals for columns. | |
pivotTable.setColumnGrand(true); | |
//Setting the PivotTable report displays a custom string in cells that contain null values. | |
pivotTable.setDisplayNullString(true); | |
pivotTable.setNullString("null"); | |
//Setting the PivotTable report's layout | |
pivotTable.setPageFieldOrder(AsposeCells.PrintOrderType.DownThenOver); | |
//Saving the Excel file | |
workbook.save(dataDir + "output.xls"); |
تنسيق المظهر يدويًا
لتنسيق كيفية ظهور تقرير الجدول المحوري يدويًا، بدلاً من استخدام تنسيقات التقرير المُعدة مسبقًا، استخدم الأساليب PivotTable.formatAll(style) و PivotTable.format(row, column, style). أنشئ كائن نمط للتنسيق المطلوب، على سبيل المثال:
const AsposeCells = require("aspose.cells.node"); | |
//For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
//The path to the documents directory. | |
var dataDir = RunExamples.GetDataDir(".") | |
//Load a template file | |
var workbook = new AsposeCells.Workbook(dataDir + "Book1.xls"); | |
//Get the first worksheet | |
var worksheet = workbook.getWorksheets().get(0); | |
var pivot = worksheet.getPivotTables().get(0); | |
pivot.setPivotTableStyleType(AsposeCells.PivotTableStyleType.PivotTableStyleDark1); | |
var style = workbook.createStyle(); | |
style.getFont().setName("Arial Black"); | |
style.setPattern(AsposeCells.BackgroundType.Solid); | |
style.setForegroundColor(AsposeCells.Color.Yellow); | |
pivot.formatAll(style); | |
//Saving the Excel file | |
workbook.save(dataDir + "output.xls"); |
كيفية تعيين خيارات تنسيق حقل الجدول المحوري
تمثل فئة PivotField حقلًا في جدول دور ، ويمكن تهيئته بعدة طرق. تُظهر العينة البرمجية أدناه كيفية:
- الوصول إلى حقول الصفوف.
- ضبط المجاميع الفرعية.
- ضبط الترتيب التلقائي.
- ضبط الإظهار التلقائي.
كيفية تعيين تنسيق حقول الصف/العمود/الصفحة
const AsposeCells = require("aspose.cells.node"); | |
//For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
//The path to the documents directory. | |
var dataDir = RunExamples.GetDataDir("."); | |
//Load a template file | |
var workbook = new AsposeCells.Workbook(dataDir + "Book1.xls"); | |
//Get the first worksheet | |
var worksheet = workbook.getWorksheets().get(0); | |
var pivotindex = 0; | |
//Accessing the PivotTable | |
var pivotTable = worksheet.getPivotTables().get(pivotindex); | |
//Setting the PivotTable report shows grand totals for rows. | |
pivotTable.setRowGrand(true); | |
//Accessing the row fields. | |
var pivotFields = pivotTable.getRowFields(); | |
//Accessing the first row field in the row fields. | |
var pivotField = pivotFields.get(0); | |
//Setting Subtotals. | |
pivotField.setSubtotals(AsposeCells.PivotFieldSubtotalType.Sum, true); | |
pivotField.setSubtotals(AsposeCells.PivotFieldSubtotalType.Count, true); | |
//Setting autosort options. | |
//Setting the field auto sort. | |
pivotField.setIsAutoSort(true); | |
//Setting the field auto sort ascend. | |
pivotField.setIsAscendSort(true); | |
//Setting the field auto sort using the field itself. | |
pivotField.setAutoSortField(-5); | |
//Setting autoShow options. | |
//Setting the field auto show. | |
pivotField.setIsAutoShow(true); | |
//Setting the field auto show ascend. | |
pivotField.setIsAscendShow(false); | |
//Setting the auto show using field(data field). | |
pivotField.setAutoShowField(0); | |
//Saving the Excel file | |
workbook.save(dataDir + "output.xls"); |
كيفية تعيين تنسيق حقول البيانات
تُظهر العينة البرمجية أدناه كيفية تعيين تنسيقات العرض وتنسيق الأرقام لحقول البيانات.
const AsposeCells = require("aspose.cells.node"); | |
//For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
//The path to the documents directory. | |
var dataDir = RunExamples.GetDataDir("."); | |
//Load a template file | |
var workbook = new AsposeCells.Workbook(dataDir + "Book1.xls"); | |
//Get the first worksheet | |
var worksheet = workbook.getWorksheets().get(0); | |
var pivotindex = 0; | |
//Accessing the PivotTable | |
var pivotTable = worksheet.getPivotTables().get(pivotindex); | |
//Accessing the data fields. | |
var pivotFields = pivotTable.getDataFields(); | |
//Accessing the first data field in the data fields. | |
var pivotField = pivotFields.get(0); | |
//Setting data display format | |
pivotField.showValuesAs(AsposeCells.PivotFieldDataDisplayFormat.PercentageOf, 1, AsposeCells.PivotItemPositionType.Next, 0); | |
//Setting number format | |
pivotField.setNumber(10); | |
//Saving the Excel file | |
workbook.save(dataDir + "output.xls"); |
كيفية مسح حقول الجدول المحوري
تحتوي فئة PivotFieldCollection على طريقة تسمى clear() تتيح لك مسح حقول الجدول الدوري. استخدمها عندما ترغب في مسح جميع حقول الجدول الدوري في المناطق، على سبيل المثال، الصفحة، العمود، الصف أو البيانات. يظهر الكود العيني أدناه كيفية مسح جميع حقول الجدول المفصلي في مجال البيانات.
const AsposeCells = require("aspose.cells.node"); | |
//For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
//The path to the documents directory. | |
var dataDir = RunExamples.GetDataDir(".") | |
//Load a template file | |
var workbook = new AsposeCells.Workbook(dataDir + "Book1.xls"); | |
//Get the first worksheet | |
var sheet = workbook.getWorksheets().get(0); | |
//Get the pivot tables in the sheet | |
var pivotTables = sheet.getPivotTables(); | |
//Get the first PivotTable | |
var pivotTable = pivotTables.get(0); | |
//Clear all the data fields | |
pivotTable.getDataFields().clear(); | |
//Add new data field | |
pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Data, "Betrag Netto FW"); | |
//Set the refresh data flag on | |
pivotTable.setRefreshDataFlag(true); | |
//Refresh and calculate the pivot table data | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
pivotTable.setRefreshDataFlag(false); | |
//Saving the Excel file | |
workbook.save(dataDir + "output.xls"); |