BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
IWorkbook sourcebook = application.Workbooks.Open("C:\\Vo1\\Vo1.xls", ExcelOpenType.Automatic);
IWorksheet sourcesheet = sourcebook.Worksheets[0];
int rowrange = sourcesheet.Columns.Length;
// only interested in three columns
IRange sourcerange = sourcesheet[1, 8, sourcesheet.Rows.Length, 10];
//add the pivot sheet
IWorksheet pivotSheet = sourcebook.Worksheets[1];
pivotSheet.Activate();
//Select the data to add in cache
IPivotCache cache = sourcebook.PivotCaches.Add(sourcesheet[1, 8, sourcesheet.Rows.Length, 10]);
//Insert the pivot table.
IPivotTable pivotTable = pivotSheet.PivotTables.Add("PivotTable1", pivotSheet["A1"], cache);
// Here is where I start having issues with what to do
pivotTable.Fields[1].Axis = PivotAxisTypes.Row;
IPivotField field = pivotSheet.PivotTables[0].Fields[2];
pivotTable.DataFields.Add(field, "Sum of Units", PivotSubtotalTypes.Sum);
Then copy the pivot table as values to a new workbook and close this one
Any snippets that would help with this - thanks