示例#1
0
 public static Excel.Range CopyPivotTable(Excel.PivotTable pt)
 {
     Excel.Application XlApp       = pt.Application;
     Excel.Worksheet   sourceSheet = (Excel.Worksheet)pt.Parent;
     sourceSheet.Select();
     pt.PivotSelect("", Excel.XlPTSelectionMode.xlDataAndLabel, true);
     Excel.Range sourceRange = (Excel.Range)XlApp.Selection;
     sourceRange.Copy();
     Excel.Worksheets sheets    = (Excel.Worksheets)XlApp.Sheets;
     Excel.Worksheet  destSheet = (Excel.Worksheet)sheets.Add();
     destSheet.Paste();
     return(destSheet.Range["A1"]);
 }