Pivot Öğesinin Mutlak Konumunu Belirtme

Contents
[ ]

Aşağıdaki örnek kod, bir Pivot Tablo oluşturur ve ardından aynı ebeveyn düğümdeki Pivot Öğelerinin konumlarını belirtir. Referansınız için kaynak Excel ve çıktı Excel dosyalarını indirebilirsiniz. Çıktı Excel dosyasını açarsanız, Pivot Öğesi “4H12”‘nin “K11” üst ebeveynindeki 0. pozisyonda olduğunu ve “DIF400”‘in 3. pozisyonda olduğunu göreceksiniz. Benzer şekilde, CA32 1. pozisyonda ve AAA3 2. pozisyonda.

//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
const AsposeCells = require("aspose.cells.node");
var wb = new AsposeCells.Workbook("source.xlsx");
var wsPivot = wb.getWorksheets().add("pvtNew Hardware");
var wsData = wb.getWorksheets().get("New Hardware - Yearly");
// Get the pivottables collection for the pivot sheet
var pivotTables = wsPivot.getPivotTables();
// Add PivotTable to the worksheet
var index = pivotTables.add("='New Hardware - Yearly'!A1:D621", "A3", "HWCounts_PivotTable");
// Get the PivotTable object
var pvtTable = pivotTables.get(index);
// Add vendor row field
pvtTable.addFieldToArea(AsposeCells.PivotFieldType.Row, "Vendor");
// Add item row field
pvtTable.addFieldToArea(AsposeCells.PivotFieldType.Row, "Item");
// Add data field
pvtTable.addFieldToArea(AsposeCells.PivotFieldType.Data, "2014");
// Turn off the subtotals for the vendor row field
var pivotField = pvtTable.getRowFields().get("Vendor");
pivotField.setSubtotals(AsposeCells.PivotFieldSubtotalType.None, true);
// Turn off grand total
pvtTable.setColumnGrand(false);
/*
* Please call the PivotTable.refreshData() and PivotTable.calculateData()
* before using PivotItem.setPosition,
* PivotItem.setPositionInSameParentNode and PivotItem.move methods.
*/
pvtTable.refreshData();
pvtTable.calculateData();
pvtTable.getRowFields().get("Item").getPivotItems().get("4H12").setPositionInSameParentNode(0);
pvtTable.getRowFields().get("Item").getPivotItems().get("DIF400").setPositionInSameParentNode(3);
/*
* As a result of using PivotItem.setPositionInSameParentNode,
* it will change the original sort sequence.
* So when you use PivotItem.setPositionInSameParentNode in another parent node.
* You need call the method named "calculateData" again.
*/
pvtTable.calculateData();
pvtTable.getRowFields().get("Item").getPivotItems().get("CA32").setPositionInSameParentNode(1);
pvtTable.getRowFields().get("Item").getPivotItems().get("AAA3").setPositionInSameParentNode(2);
// Save file
wb.save("output_out.xlsx");