إنشاء جداول محورية ورسوم بيانية محورية
الجدول المحوري هو ملخص تفاعلي للسجلات. على سبيل المثال، قد تحتوي على مئات الإدخالات الخاصة بالفواتير في قائمة داخل صفحة العمل. يمكن للجدول المحوري إجمالي الفواتير حسب العميل، المنتج أو التاريخ. باستخدام مايكروسوفت إكسل يمكن بسرعة إعادة ترتيب المعلومات في الجدول المحوري عن طريق سحب الأزرار إلى موقع جديد.
الرسم البياني المحوري هو تمثيل رسومي تفاعلي للبيانات في الجدول المحوري. تم إدخال الرسوم البيانية المحورية في إكسل 2000. باستخدام الرسم البياني المحوري يصبح أسهل فهم البيانات نظرًا لأن الجدول المحوري يقوم تلقائيًا بإنشاء المجاميع الفرعية والمجاميع.
Aspose.Cells for Node.js via C++ يدعم الجداول المحورية و الرسوم البيانية المحورية.
إضافة جداول و مخططات محورية باستخدام Aspose.Cells for Node.js via C++
توفر Aspose.Cells for Node.js via C++ مجموعة مميزة من الفئات المستخدمة لإنشاء جداول محورية. تُستخدم هذه الفئات لإنشاء وتعيين كائنات الجدول المحوري، والتي تعمل كأساس لبناء كائن الجدول المحوري:
- PivotField، حقل في تقرير جدول محوري.
- PivotFields، مجموعة من جميع كائنات PivotField في جدول محوري.
- PivotTable، تقرير PivotTable على صفحة العمل.
- PivotTables، مجموعة من جميع كائنات PivotTable على صفحة العمل.
تحضير لاستخدام Aspose.Cells for Node.js via C++
- تثبيت Aspose.Cells for Node.js via C++ من NPM، استخدم الأمر التالي: $ npm install aspose.cells.node.
- يمكنك أيضًا اتباع التعليمات خطوة بخطوة حول كيفية تثبيت “Aspose.Cells for Node.js via C++” لبيئة المطور الخاصة بك.
كيفية إضافة جدول محوري باستخدام Aspose.Cells for Node.js via C++
لإنشاء جدول محوري باستخدام Aspose.Cells for Node.js via C++:
- أضف بعض البيانات إلى خلايا ورق العمل باستخدام طريقة put_value لكائن الخلية. يمكنك أيضًا استخدام ملف قالب مملوء بالفعل بالبيانات. ستُستخدم البيانات كمصدر بيانات الجدول المحوري.
- أضف جدول محوري إلى ورقة العمل عن طريق استدعاء طريقة add في مجموعة PivotTables (مغلّفة في كائن الورقة).
- الوصول إلى كائن PivotTable الجديد من مجموعة PivotTables عن طريق تمرير الفهرس الخاص به. ثم استخدم أي من كائنات جدول الجدول المحوري المحتوية في كائن PivotTable لإدارة الجدول.
تم إعطاء أمثلة الكود أدناه.
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(".");; | |
//Instantiating an Workbook object | |
var workbook = new AsposeCells.Workbook(); | |
//Obtaining the reference of the first worksheet | |
var sheet = workbook.getWorksheets().get(0); | |
//Name the sheet | |
sheet.setName("Data");; | |
var cells = sheet.getCells(); | |
//Setting the values to the cells | |
var cell = cells.get("A1"); | |
cell.putValue("Employee"); | |
cell = cells.get("B1"); | |
cell.putValue("Quarter"); | |
cell = cells.get("C1"); | |
cell.putValue("Product"); | |
cell = cells.get("D1"); | |
cell.putValue("Continent"); | |
cell = cells.get("E1"); | |
cell.putValue("Country"); | |
cell = cells.get("F1"); | |
cell.putValue("Sale"); | |
cell = cells.get("A2"); | |
cell.putValue("David"); | |
cell = cells.get("A3"); | |
cell.putValue("David"); | |
cell = cells.get("A4"); | |
cell.putValue("David"); | |
cell = cells.get("A5"); | |
cell.putValue("David"); | |
cell = cells.get("A6"); | |
cell.putValue("James"); | |
cell = cells.get("A7"); | |
cell.putValue("James"); | |
cell = cells.get("A8"); | |
cell.putValue("James"); | |
cell = cells.get("A9"); | |
cell.putValue("James"); | |
cell = cells.get("A10"); | |
cell.putValue("James"); | |
cell = cells.get("A11"); | |
cell.putValue("Miya"); | |
cell = cells.get("A12"); | |
cell.putValue("Miya"); | |
cell = cells.get("A13"); | |
cell.putValue("Miya"); | |
cell = cells.get("A14"); | |
cell.putValue("Miya"); | |
cell = cells.get("A15"); | |
cell.putValue("Miya"); | |
cell = cells.get("A16"); | |
cell.putValue("Miya"); | |
cell = cells.get("A17"); | |
cell.putValue("Miya"); | |
cell = cells.get("A18"); | |
cell.putValue("Elvis"); | |
cell = cells.get("A19"); | |
cell.putValue("Elvis"); | |
cell = cells.get("A20"); | |
cell.putValue("Elvis"); | |
cell = cells.get("A21"); | |
cell.putValue("Elvis"); | |
cell = cells.get("A22"); | |
cell.putValue("Elvis"); | |
cell = cells.get("A23"); | |
cell.putValue("Elvis"); | |
cell = cells.get("A24"); | |
cell.putValue("Elvis"); | |
cell = cells.get("A25"); | |
cell.putValue("Jean"); | |
cell = cells.get("A26"); | |
cell.putValue("Jean"); | |
cell = cells.get("A27"); | |
cell.putValue("Jean"); | |
cell = cells.get("A28"); | |
cell.putValue("Ada"); | |
cell = cells.get("A29"); | |
cell.putValue("Ada"); | |
cell = cells.get("A30"); | |
cell.putValue("Ada"); | |
cell = cells.get("B2"); | |
cell.putValue("1"); | |
cell = cells.get("B3"); | |
cell.putValue("2"); | |
cell = cells.get("B4"); | |
cell.putValue("3"); | |
cell = cells.get("B5"); | |
cell.putValue("4"); | |
cell = cells.get("B6"); | |
cell.putValue("1"); | |
cell = cells.get("B7"); | |
cell.putValue("2"); | |
cell = cells.get("B8"); | |
cell.putValue("3"); | |
cell = cells.get("B9"); | |
cell.putValue("4"); | |
cell = cells.get("B10"); | |
cell.putValue("4"); | |
cell = cells.get("B11"); | |
cell.putValue("1"); | |
cell = cells.get("B12"); | |
cell.putValue("1"); | |
cell = cells.get("B13"); | |
cell.putValue("2"); | |
cell = cells.get("B14"); | |
cell.putValue("2"); | |
cell = cells.get("B15"); | |
cell.putValue("3"); | |
cell = cells.get("B16"); | |
cell.putValue("4"); | |
cell = cells.get("B17"); | |
cell.putValue("4"); | |
cell = cells.get("B18"); | |
cell.putValue("1"); | |
cell = cells.get("B19"); | |
cell.putValue("1"); | |
cell = cells.get("B20"); | |
cell.putValue("2"); | |
cell = cells.get("B21"); | |
cell.putValue("3"); | |
cell = cells.get("B22"); | |
cell.putValue("3"); | |
cell = cells.get("B23"); | |
cell.putValue("4"); | |
cell = cells.get("B24"); | |
cell.putValue("4"); | |
cell = cells.get("B25"); | |
cell.putValue("1"); | |
cell = cells.get("B26"); | |
cell.putValue("2"); | |
cell = cells.get("B27"); | |
cell.putValue("3"); | |
cell = cells.get("B28"); | |
cell.putValue("1"); | |
cell = cells.get("B29"); | |
cell.putValue("2"); | |
cell = cells.get("B30"); | |
cell.putValue("3"); | |
cell = cells.get("C2"); | |
cell.putValue("Maxilaku"); | |
cell = cells.get("C3"); | |
cell.putValue("Maxilaku"); | |
cell = cells.get("C4"); | |
cell.putValue("Chai"); | |
cell = cells.get("C5"); | |
cell.putValue("Maxilaku"); | |
cell = cells.get("C6"); | |
cell.putValue("Chang"); | |
cell = cells.get("C7"); | |
cell.putValue("Chang"); | |
cell = cells.get("C8"); | |
cell.putValue("Chang"); | |
cell = cells.get("C9"); | |
cell.putValue("Chang"); | |
cell = cells.get("C10"); | |
cell.putValue("Chang"); | |
cell = cells.get("C11"); | |
cell.putValue("Geitost"); | |
cell = cells.get("C12"); | |
cell.putValue("Chai"); | |
cell = cells.get("C13"); | |
cell.putValue("Geitost"); | |
cell = cells.get("C14"); | |
cell.putValue("Geitost"); | |
cell = cells.get("C15"); | |
cell.putValue("Maxilaku"); | |
cell = cells.get("C16"); | |
cell.putValue("Geitost"); | |
cell = cells.get("C17"); | |
cell.putValue("Geitost"); | |
cell = cells.get("C18"); | |
cell.putValue("Ikuru"); | |
cell = cells.get("C19"); | |
cell.putValue("Ikuru"); | |
cell = cells.get("C20"); | |
cell.putValue("Ikuru"); | |
cell = cells.get("C21"); | |
cell.putValue("Ikuru"); | |
cell = cells.get("C22"); | |
cell.putValue("Ipoh Coffee"); | |
cell = cells.get("C23"); | |
cell.putValue("Ipoh Coffee"); | |
cell = cells.get("C24"); | |
cell.putValue("Ipoh Coffee"); | |
cell = cells.get("C25"); | |
cell.putValue("Chocolade"); | |
cell = cells.get("C26"); | |
cell.putValue("Chocolade"); | |
cell = cells.get("C27"); | |
cell.putValue("Chocolade"); | |
cell = cells.get("C28"); | |
cell.putValue("Chocolade"); | |
cell = cells.get("C29"); | |
cell.putValue("Chocolade"); | |
cell = cells.get("C30"); | |
cell.putValue("Chocolade"); | |
cell = cells.get("D2"); | |
cell.putValue("Asia"); | |
cell = cells.get("D3"); | |
cell.putValue("Asia"); | |
cell = cells.get("D4"); | |
cell.putValue("Asia"); | |
cell = cells.get("D5"); | |
cell.putValue("Asia"); | |
cell = cells.get("D6"); | |
cell.putValue("Europe"); | |
cell = cells.get("D7"); | |
cell.putValue("Europe"); | |
cell = cells.get("D8"); | |
cell.putValue("Europe"); | |
cell = cells.get("D9"); | |
cell.putValue("Europe"); | |
cell = cells.get("D10"); | |
cell.putValue("Europe"); | |
cell = cells.get("D11"); | |
cell.putValue("America"); | |
cell = cells.get("D12"); | |
cell.putValue("America"); | |
cell = cells.get("D13"); | |
cell.putValue("America"); | |
cell = cells.get("D14"); | |
cell.putValue("America"); | |
cell = cells.get("D15"); | |
cell.putValue("America"); | |
cell = cells.get("D16"); | |
cell.putValue("America"); | |
cell = cells.get("D17"); | |
cell.putValue("America"); | |
cell = cells.get("D18"); | |
cell.putValue("Europe"); | |
cell = cells.get("D19"); | |
cell.putValue("Europe"); | |
cell = cells.get("D20"); | |
cell.putValue("Europe"); | |
cell = cells.get("D21"); | |
cell.putValue("Oceania"); | |
cell = cells.get("D22"); | |
cell.putValue("Oceania"); | |
cell = cells.get("D23"); | |
cell.putValue("Oceania"); | |
cell = cells.get("D24"); | |
cell.putValue("Oceania"); | |
cell = cells.get("D25"); | |
cell.putValue("Africa"); | |
cell = cells.get("D26"); | |
cell.putValue("Africa"); | |
cell = cells.get("D27"); | |
cell.putValue("Africa"); | |
cell = cells.get("D28"); | |
cell.putValue("Africa"); | |
cell = cells.get("D29"); | |
cell.putValue("Africa"); | |
cell = cells.get("D30"); | |
cell.putValue("Africa"); | |
cell = cells.get("E2"); | |
cell.putValue("China"); | |
cell = cells.get("E3"); | |
cell.putValue("India"); | |
cell = cells.get("E4"); | |
cell.putValue("Korea"); | |
cell = cells.get("E5"); | |
cell.putValue("India"); | |
cell = cells.get("E6"); | |
cell.putValue("France"); | |
cell = cells.get("E7"); | |
cell.putValue("France"); | |
cell = cells.get("E8"); | |
cell.putValue("Germany"); | |
cell = cells.get("E9"); | |
cell.putValue("Italy"); | |
cell = cells.get("E10"); | |
cell.putValue("France"); | |
cell = cells.get("E11"); | |
cell.putValue("U.S."); | |
cell = cells.get("E12"); | |
cell.putValue("U.S."); | |
cell = cells.get("E13"); | |
cell.putValue("Brazil"); | |
cell = cells.get("E14"); | |
cell.putValue("U.S."); | |
cell = cells.get("E15"); | |
cell.putValue("U.S."); | |
cell = cells.get("E16"); | |
cell.putValue("Canada"); | |
cell = cells.get("E17"); | |
cell.putValue("U.S."); | |
cell = cells.get("E18"); | |
cell.putValue("Italy"); | |
cell = cells.get("E19"); | |
cell.putValue("France"); | |
cell = cells.get("E20"); | |
cell.putValue("Italy"); | |
cell = cells.get("E21"); | |
cell.putValue("New Zealand"); | |
cell = cells.get("E22"); | |
cell.putValue("Australia"); | |
cell = cells.get("E23"); | |
cell.putValue("Australia"); | |
cell = cells.get("E24"); | |
cell.putValue("New Zealand"); | |
cell = cells.get("E25"); | |
cell.putValue("S.Africa"); | |
cell = cells.get("E26"); | |
cell.putValue("S.Africa"); | |
cell = cells.get("E27"); | |
cell.putValue("S.Africa"); | |
cell = cells.get("E28"); | |
cell.putValue("Egypt"); | |
cell = cells.get("E29"); | |
cell.putValue("Egypt"); | |
cell = cells.get("E30"); | |
cell.putValue("Egypt"); | |
cell = cells.get("F2"); | |
cell.putValue(2000) | |
cell = cells.get("F3"); | |
cell.putValue(500) | |
cell = cells.get("F4"); | |
cell.putValue(1200) | |
cell = cells.get("F5"); | |
cell.putValue(1500) | |
cell = cells.get("F6"); | |
cell.putValue(500) | |
cell = cells.get("F7"); | |
cell.putValue(1500) | |
cell = cells.get("F8"); | |
cell.putValue(800) | |
cell = cells.get("F9"); | |
cell.putValue(900) | |
cell = cells.get("F10"); | |
cell.putValue(500) | |
cell = cells.get("F11"); | |
cell.putValue(1600) | |
cell = cells.get("F12"); | |
cell.putValue(600) | |
cell = cells.get("F13"); | |
cell.putValue(2000) | |
cell = cells.get("F14"); | |
cell.putValue(500) | |
cell = cells.get("F15"); | |
cell.putValue(900) | |
cell = cells.get("F16"); | |
cell.putValue(700) | |
cell = cells.get("F17"); | |
cell.putValue(1400) | |
cell = cells.get("F18"); | |
cell.putValue(1350) | |
cell = cells.get("F19"); | |
cell.putValue(300) | |
cell = cells.get("F20"); | |
cell.putValue(500) | |
cell = cells.get("F21"); | |
cell.putValue(1000) | |
cell = cells.get("F22"); | |
cell.putValue(1500) | |
cell = cells.get("F23"); | |
cell.putValue(1500) | |
cell = cells.get("F24"); | |
cell.putValue(1600) | |
cell = cells.get("F25"); | |
cell.putValue(1000) | |
cell = cells.get("F26"); | |
cell.putValue(1200) | |
cell = cells.get("F27"); | |
cell.putValue(1300) | |
cell = cells.get("F28"); | |
cell.putValue(1500) | |
cell = cells.get("F29"); | |
cell.putValue(1400) | |
cell = cells.get("F30"); | |
cell.putValue(1000) | |
//Adding a new sheet | |
var sheet2 = workbook.getWorksheets().get(workbook.getWorksheets().add()); | |
//Naming the sheet | |
sheet2.setName("PivotTable"); | |
//Getting the pivottables collection in the sheet | |
var pivotTables = sheet2.getPivotTables(); | |
//Adding a PivotTable to the worksheet | |
var index = pivotTables.add("=Data!A1:F30", "B3", "PivotTable1"); | |
//Accessing the instance of the newly added PivotTable | |
var pivotTable = pivotTables.get(index); | |
//Showing the grand totals | |
pivotTable.setRowGrand(true); | |
pivotTable.setColumnGrand(true); | |
//Setting the PivotTable report is automatically formatted | |
pivotTable.setIsAutoFormat(true); | |
//Setting the PivotTable autoformat type. | |
pivotTable.setAutoFormatType(AsposeCells.PivotTableAutoFormatType.Report6); | |
//Draging the first field to the row area. | |
pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 0); | |
//Draging the third field to the row area. | |
pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 2); | |
//Draging the second field to the row area. | |
pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 1); | |
//Draging the fourth field to the column area. | |
pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Column, 3); | |
//Draging the fifth field to the data area. | |
pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Data, 5); | |
//Setting the number format of the first data field | |
pivotTable.getDataFields().get(0).setNumberFormat("$#,##0.00"); | |
//Saving the Excel file | |
workbook.save(dataDir + "pivotTable_test.out.xlsx"); |
كيفية إضافة مخطط محوري باستخدام مكتبة Aspose.Cells for Node.js via C++
لإنشاء مخطط Pivot باستخدام Aspose.Cells for Node.js via C++:
- أضف رسم بياني.
- قم بتعيين PivotSource للرسم البياني للإشارة إلى جدول محوري موجود في جدول البيانات.
- قم بتعيين سمات أخرى.
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("."); | |
//Instantiating an Workbook object | |
//Opening the excel file | |
var workbook = new AsposeCells.Workbook(dataDir + "pivotTable_test.xlsx"); | |
//Adding a new sheet | |
var sheet3 = workbook.getWorksheets().get(workbook.getWorksheets().add(AsposeCells.SheetType.Chart)); | |
//Naming the sheet | |
sheet3.setName("PivotChart"); | |
//Adding a column chart | |
index = sheet3.getCharts().add(AsposeCells.ChartType.Column, 0, 5, 28, 16); | |
//Setting the pivot chart data source | |
sheet3.getCharts().get(index).setPivotSource("PivotTable!PivotTable1"); | |
sheet3.getCharts().get(index).setHidePivotFieldButtons(false); | |
//Saving the Excel file | |
workbook.save(dataDir + "pivotChart_test_out.xlsx"); |