Hi
It's a shame it is not possible to set the exact position you want. In any case I can't seem to get 'Move' to work properly. Depending upon which data item I try to move either nothing happens or it moves the wrong number of places. Consider the following code, in which I try to move "4H12" by 4 positions but it only moves 1 position:
Workbook wb = new Workbook(@"F:\Model_Outputs\Results\PivotTest.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;
// THIS ONLY SEEMS TO MOVE 4H12 DOWN BY 1 POSITION??
pvtTable.RowFields["Item"].PivotItems["4H12"].Move(4);
// save file
wb.Save(@"F:\Model_Outputs\Results\PivotTest2.xlsx");
I have attached a sample file, the first tab contains the data used in the pivot table, the second tab shows the pivot without calling the 'Move' method and the third tab shows the pivot when the 'Move' method is called - it only moves by 1 position.