question

15377772 avatar image
0 Votes"
15377772 asked emizhang-msft edited

Creating a Chart in PowerPoint(VSOT)

I am building an add-in in C# (VSOT) to automatically create and edit charts.

I was able to add the chart to the slide and reflect the data and chart.
However, when I try to edit the data manually, I get the attached error.

Is there any way to keep the link between the chart data edited from the code working properly?


 public void setGraph_Cross(Slide targetSlide, object[,] srcData)
 {
     //Shape chart;
     var chart = getChartFromSlide(targetSlide);
        
     //exell app invisibled
     Workbook workbook = chart.ChartData.Workbook;
     var exapp = workbook.Application;
     exapp.Visible = false;
        
     //get worksheet
     Worksheet sheet = ((Workbook)chart.ChartData.Workbook).Sheets[1];
     sheet.Range["A3", "D5"].Clear();
     sheet.Range["C1", "D5"].Clear();
        
     //set data
     var cell_Start = sheet.Range["A1"];
     var cell_End = cell_Start.get_Offset(srcData.GetLength(0) - 1, srcData.GetLength(1) - 1);
     var targetRange = sheet.get_Range(cell_Start, cell_End);
     targetRange.Value = srcData;
    
     //set data area
     chart.SetSourceData(sheet.Name + "!" + sheet.UsedRange.Address);
        
     //chart update
     chart.Refresh();
    
     //Close&Save workbook
     workbook.Close(true);
     releaseObjects(targetRange, cell_Start, cell_End, sheet, workbook);
     if (exapp.Workbooks.Count == 0)
     {
         exapp.Quit();
         releaseObjects(exapp);
     }
 }



167483-image.png



office-vba-devoffice-vsto-com-dev
image.png (5.5 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers