簡體   English   中英

如何將圖表從Excel文件復制到電源點?

[英]How to copy chart from an excel file to power point?

我有一個C#代碼構建一個包含少量圖表的excel文件。 我通過Microsoft.Office.Interop.Excel 12使用Excel。

這工作正常,但同時我需要生成一個包含相同精確圖表的PowerPoint演示文稿。

有沒有辦法將Microsoft.Office.Interop.Excel.ChartObject復制到PowerPoint文件? 或者以編程方式將這些圖表復制到PowerPoint演示文稿的任何其他方法?

我想這應該有效

            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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM