C # How to refresh Powerpoint chart without opening Excel

I have a C # Powerpoint plugin that returns chart data from a Web API and updates the chart in the current Powerpoint slide. This works great when I actively open Excel chart data, although I soon set the Visible flag to false. Here is the code:

        // Activate the workbook but keep it hidden           
        chart.ChartData.Activate();
        chart.ChartData.Workbook.Application.Visible = false;

        // Get the Excel datasheet of the new chart and clear all data
        var workbook = (Microsoft.Office.Interop.Excel.Workbook)chart.ChartData.Workbook;
        var datasheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1];
        datasheet.Cells.ClearContents();

        // Populate the chart with the api data
        // ...

      

Is there a way to set the visibility flag in Excel before opening it to prevent this from happening? Or is there another way to transfer my data to the chart without using Excel?

+1


source to share





All Articles