I am trying to move a pivot table to VSTO and not succeed at all. My logic was to find the range of the pivot table, cut it out and paste it into a new range, where I am sure that there is no data on the sheet.
public static void MovePivotTable(string sheetName, PivotTable pivotTable, int newX, int newY, int width, int height)
{
try
{
Worksheet worksheet = GetOrCreateWorksheet(sheetName);
Range topLeft = (Range)worksheet.Cells[newX, newY];
Range bottomRight = (Range)worksheet.Cells[newX + width, newY + height];
Range newRange = worksheet.get_Range(topLeft, bottomRight);
pivotTable.TableRange1.Cut(Missing.Value);
newRange.PasteSpecial(XlPasteType.xlPasteAll, XlPasteSpecialOperation.xlPasteSpecialOperationNone,
Missing.Value, Missing.Value);
return;
}
catch (Exception)
{
}
finally
{
}
}
However, I always get an exception. Or: - PasteSpecial error. - Something along the lines that it is impossible to change the pivot table.
Has anyone ever done this? Can they confirm that this is really possible or not? Any sample code?
Thanks a lot sean
source
share