تحديد الموضع المطلق للعنصر المحوري
Contents
[
Hide
]
في بعض الأحيان ، يحتاج المستخدم إلى تحديد الموضع المطلق للعناصر المحورية ، وقد كشف Aspose.Cells API عن بعض الخصائص الجديدة وطريقة لتحقيق متطلبات المستخدم.
- مضافPivotItem. الوظيفة الخاصية التي يمكن استخدامها لتحديد فهرس الموضع في جميع عناصر PivotItems بغض النظر عن العقدة الأصلية. مضافPivotItem.PositionInSameParentNode الخاصية التي يمكن استخدامها لتحديد فهرس الموضع في PivotItems ضمن نفس العقدة الأصلية.
- مضافPivotItem.Move (عدد صحيح ، منطقي هو نفس الأصل)لتحريك العنصر لأعلى أو لأسفل استنادًا إلى قيمة الجرد ، حيث يكون العدد هو رقم الموضع لتحريك PivotItem لأعلى أو لأسفل. إذا كانت قيمة العد أقل من الصفر ، فسيتم نقل العنصر لأعلى حيث كما لو كانت قيمة العد أكبر من الصفر ، سينتقل PivotItem إلى أسفل ، والنوع المنطقي هو نفس المعلمة الأصلية تحدد ما إذا كان يجب تنفيذ عملية النقل في نفس العقدة الأصلية أم لا.
- عفا عليها الزمنPivotItem.Move (عدد العمليات) لذلك يُقترح استخدام الطريقة المضافة حديثًاPivotItem.Move (عدد صحيح ، منطقي هو نفس الأصل) بدلاً من.
ينشئ نموذج التعليمات البرمجية التالي جدولاً محوريًا ثم يحدد مواضع العناصر المحورية في نفس العقدة الأصلية. يمكنك تنزيل ملفمصدر Excel والإخراج إكسل ملفات للرجوع اليها. إذا فتحت ملف Excel الناتج ، فسترى العنصر المحوري “4H12” في الموضع 0 في الأصل “K11” و “DIF400” في المركز الثالث. وبالمثل ، فإن CA32 في الموضع 1 و AAA3 في الموضع 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook wb = new Workbook(dataDir + "source.xlsx"); | |
Worksheet wsPivot = wb.Worksheets.Add("pvtNew Hardware"); | |
Worksheet wsData = wb.Worksheets["New Hardware - Yearly"]; | |
// Get the pivottables collection for the pivot sheet | |
PivotTableCollection pivotTables = wsPivot.PivotTables; | |
// Add PivotTable to the worksheet | |
int index = pivotTables.Add("='New Hardware - Yearly'!A1:D621", "A3", "HWCounts_PivotTable"); | |
// Get the PivotTable object | |
PivotTable pvtTable = pivotTables[index]; | |
// Add vendor row field | |
pvtTable.AddFieldToArea(PivotFieldType.Row, "Vendor"); | |
// Add item row field | |
pvtTable.AddFieldToArea(PivotFieldType.Row, "Item"); | |
// Add data field | |
pvtTable.AddFieldToArea(PivotFieldType.Data, "2014"); | |
// Turn off the subtotals for the vendor row field | |
PivotField pivotField = pvtTable.RowFields["Vendor"]; | |
pivotField.SetSubtotals(PivotFieldSubtotalType.None, true); | |
// Turn off grand total | |
pvtTable.ColumnGrand = false; | |
/* | |
* Please call the PivotTable.RefreshData() and PivotTable.CalculateData() | |
* before using PivotItem.Position, | |
* PivotItem.PositionInSameParentNode and PivotItem.Move(int count, bool isSameParent). | |
*/ | |
pvtTable.RefreshData(); | |
pvtTable.CalculateData(); | |
pvtTable.RowFields["Item"].PivotItems["4H12"].PositionInSameParentNode = 0; | |
pvtTable.RowFields["Item"].PivotItems["DIF400"].PositionInSameParentNode = 3; | |
/* | |
* As a result of using PivotItem.PositionInSameParentNode, | |
* it will change the original sort sequence. | |
* So when you use PivotItem.PositionInSameParentNode in another parent node. | |
* You need call the method named "CalculateData" again. | |
*/ | |
pvtTable.CalculateData(); | |
pvtTable.RowFields["Item"].PivotItems["CA32"].PositionInSameParentNode = 1; | |
pvtTable.RowFields["Item"].PivotItems["AAA3"].PositionInSameParentNode = 2; | |
// Save file | |
wb.Save(dataDir + "output_out.xlsx"); |
يرجى ملاحظة أنه من الضروري استدعاء أساليب PivotTable.RefreshData و PivotTable.CalculateData قبل استخدامPivotItem. الوظيفة, PivotItem.PositionInSameParentNode خصائص وPivotItem.Move (عدد صحيح ، منطقي هو نفس الأصل) طريقة.