Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C#: How to copy excel cell range and chart data to power point slides

C#: How to copy excel cell range and chart data to power point slides

Scheduled Pinned Locked Moved C#
csharpcomdata-structurestutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tridip Bhattacharjee
    wrote on last edited by
    #1

    i have data and chart in excel work sheet which i need to copy at run time from excel to power point slides. i have a code which is working fine but the code only can copy chart data to excel sheet not range data. please see the scree shot of my excel. so anyone can get idea how data is there in my work sheet which i need to copy to power point slide programmatically. enter image description here screen shot url....please see it. [screen shot url] here is code which i am using to copy range data and chart data to power point dynamically.

    private void Form1_Load(object sender, EventArgs e)
    {
    pptNS.ApplicationClass powerpointApplication = null;
    pptNS.Presentation pptPresentation = null;
    pptNS.Slide pptSlide = null;
    pptNS.ShapeRange shapeRange = null;

    xlNS.ApplicationClass excelApplication = null;
    xlNS.Workbook excelWorkBook = null;
    xlNS.Worksheet targetSheet = null;
    xlNS.ChartObjects chartObjects = null;
    xlNS.ChartObject existingChartObject = null;
    xlNS.Range destRange = null;
    
    string paramPresentationPath = @"D:\\test\\Chart Slide.pptx";
    string paramWorkbookPath = @"D:\\test\\MyExcelData.xlsx";
    object paramMissing = Type.Missing;
    
    
    try
    {
        // Create an instance of PowerPoint.
        powerpointApplication = new pptNS.ApplicationClass();
    
        // Create an instance Excel.          
        excelApplication = new xlNS.ApplicationClass();
    
        // Open the Excel workbook containing the worksheet with the chart
        // data.
        excelWorkBook = excelApplication.Workbooks.Open(paramWorkbookPath,
                        paramMissing, paramMissing, paramMissing,
                        paramMissing, paramMissing, paramMissing,
                        paramMissing, paramMissing, paramMissing,
                        paramMissing, paramMissing, paramMissing,
                        paramMissing, paramMissing);
    
        // Get the worksheet that contains the chart.
        targetSheet =
            (xlNS.Worksheet)(excelWorkBook.Worksheets\["Spain"\]);
    
        // Get the ChartObjects collection for the sheet.
        chartObjects =
            (xlNS.ChartObjects)(targetSheet.ChartObjects(paramMissing));
    
    
    
        // Create a PowerPoint presentation.
        pptPresentation = powerpointApplication.Presentations.Add(
    
    R 1 Reply Last reply
    0
    • T Tridip Bhattacharjee

      i have data and chart in excel work sheet which i need to copy at run time from excel to power point slides. i have a code which is working fine but the code only can copy chart data to excel sheet not range data. please see the scree shot of my excel. so anyone can get idea how data is there in my work sheet which i need to copy to power point slide programmatically. enter image description here screen shot url....please see it. [screen shot url] here is code which i am using to copy range data and chart data to power point dynamically.

      private void Form1_Load(object sender, EventArgs e)
      {
      pptNS.ApplicationClass powerpointApplication = null;
      pptNS.Presentation pptPresentation = null;
      pptNS.Slide pptSlide = null;
      pptNS.ShapeRange shapeRange = null;

      xlNS.ApplicationClass excelApplication = null;
      xlNS.Workbook excelWorkBook = null;
      xlNS.Worksheet targetSheet = null;
      xlNS.ChartObjects chartObjects = null;
      xlNS.ChartObject existingChartObject = null;
      xlNS.Range destRange = null;
      
      string paramPresentationPath = @"D:\\test\\Chart Slide.pptx";
      string paramWorkbookPath = @"D:\\test\\MyExcelData.xlsx";
      object paramMissing = Type.Missing;
      
      
      try
      {
          // Create an instance of PowerPoint.
          powerpointApplication = new pptNS.ApplicationClass();
      
          // Create an instance Excel.          
          excelApplication = new xlNS.ApplicationClass();
      
          // Open the Excel workbook containing the worksheet with the chart
          // data.
          excelWorkBook = excelApplication.Workbooks.Open(paramWorkbookPath,
                          paramMissing, paramMissing, paramMissing,
                          paramMissing, paramMissing, paramMissing,
                          paramMissing, paramMissing, paramMissing,
                          paramMissing, paramMissing, paramMissing,
                          paramMissing, paramMissing);
      
          // Get the worksheet that contains the chart.
          targetSheet =
              (xlNS.Worksheet)(excelWorkBook.Worksheets\["Spain"\]);
      
          // Get the ChartObjects collection for the sheet.
          chartObjects =
              (xlNS.ChartObjects)(targetSheet.ChartObjects(paramMissing));
      
      
      
          // Create a PowerPoint presentation.
          pptPresentation = powerpointApplication.Presentations.Add(
      
      R Offline
      R Offline
      realJSOP
      wrote on last edited by
      #2

      What you should do is find out how to do it manually, and once you know nomenclature, you'll know how to google how to do it in code. Here's a place to start: [Import data from Excel into PowerPoint - PowerPoint](https://support.office.com/en-us/article/Import-data-from-Excel-into-PowerPoint-3ec295e9-1bfd-47ff-8d7d-8b838caef853)

      ".45 ACP - because shooting twice is just silly" - JSOP, 2010
      -----
      You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
      -----
      When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups