我想這應該工作
using xlNS = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.PowerPoint;
xlNS.ApplicationClass excelApplication = null;
xlNS.Workbook excelWorkBook = null;
xlNS.Worksheet targetSheet = null;
xlNS.ChartObjects chartObjects = null;
xlNS.ChartObject existingChartObject = null;
Microsoft.Office.Interop.PowerPoint.ShapeRange shapeRange = null;
Microsoft.Office.Interop.PowerPoint.Slide CurSlide;
excelApplication = new xlNS.ApplicationClass();//Create New Excel
excelWorkBook = excelApplication.Workbooks.Open(Excelpath,
paramMissing, paramMissing, paramMissing, paramMissing, paramMissing,
paramMissing, paramMissing, paramMissing, paramMissing, paramMissing,
paramMissing, paramMissing, paramMissing, paramMissing);
Ws = (Excel.Worksheet)excelWorkBook.Worksheets[6];//Your Sheet that contain Chart
Ws.Activate();
targetSheet = (xlNS.Worksheet)(excelWorkBook.Worksheets["SheetName"]);
chartObjects = (xlNS.ChartObjects)(targetSheet.ChartObjects(paramMissing));
existingChartObject = (xlNS.ChartObject)(chartObjects.Item(1));
existingChartObject.Copy();
shapeRange = CurSlide.Shapes.Paste();//Paste it to your Current Slide
shapeRange.Left = 435;
shapeRange.Top = 80; //Formatting your chart
你可以建立圖表直接與VBA到PowerPoint,Excel中使用最多(幾乎所有)相同的方法可用。除非您需要* Excel工作簿中的圖表出於某種其他原因。 –
我意識到這不是一個在兩個不同的應用程序之間複製對象的最佳解決方案,但是因爲我需要給用戶一個選擇,如果他希望這個圖表是Excel或PowerPoint,或者兩者同時我看不出有任何意義, PowerPoint已經有一個用於Excel的PowerPoint。 – Nelrum