I'm developing a C# application that creates a scatter/line chart in a
PowerPoint presentation. I need to populate the chart's datasheet with
12,000 data points. I can do it one cell at a time, but this approach is far
to slow.
As far as I can tell, the only other options are to use the Paste or
ImportData methods of a range object. I have not attempted the ImportData
method because I would rather not have to create an intermediate file. I
have attempted to use the paste method, but it always throws a "Paste
operation failed" error. Here is a code snippet:
// populate an array of data (1000 data points per row)
int rowCount = 1000;
float [] probability = new float[rowCount];
for (int i=0; i < rowCount; i++)
{
probability[i] = ((float)(i+1)) / (((float)rowCount)/100.0f);
}
// Call my custom object to get an instance of PowerPoint
application = MSOfficeApp.GetPowerPointInstance();
// Create a new presentation
presentation = application.Presentations.Add(MsoTriState.msoTrue);
// Create a slide
PowerPoint.Slide slide = _presentation.Slides.Add(1,
PowerPoint.PpSlideLayout.ppLayoutBlank);
// Create a chart
Graph.Chart graphChart = (Graph.Chart)
slide.Shapes.AddOLEObject(50,50,640,480,"MSGraph.Chart.8", "",
MsoTriState.msoFalse, "", 0, "",
MsoTriState.msoFalse).OLEFormat.Object;
// Create a datasheet
Graph.DataSheet datasheet = graphChart.Application.DataSheet;
// Create a range 1 column by 1000 rows
Graph.Range r = (Graph.Range) datasheet.get_Range(datasheet.Cells[2,1],
datasheet.Cells[rowCount+1,1]);
// Copy the array to the clipboard
Clipboard.SetDataObject(probability);
// Paste from clipboard to range in datasheet
r.Paste(false);
I haven't been able to find a useful reference/examples for using
Microsoft.Office.Interop.Graph, so any suggestions would be appreciated.
Also, any helpful pointers on using the ImportData method would be
appreciated, as it may be my fallback solution.
Cindy M -WordMVP- - 26 Jul 2006 14:38 GMT
Hi =?Utf-8?B?VGVycnlD?=,
If you put this array on the clipboard, then (manually) paste into something
like Notepad or Word, what do you get?
In general terms, I think MS Graph expects something in an RTF (or maybe HTML)
"flat table" format. It's possible to copy/paste a Word table, for instance. MS
Graph also accepts a delimited text format. But an array...? I don't think it's
that sophisticated :-)
When working with Office apps it's important to keep in mind that many of them
are strongly oriented to the UI. Automation capabilities are an "after thought",
especially with "step-children" like MS Graph.
> I'm developing a C# application that creates a scatter/line chart in a
> PowerPoint presentation. I need to populate the chart's datasheet with
[quoted text clipped - 47 lines]
> I haven't been able to find a useful reference/examples for using
> Microsoft.Office.Interop.Graph, so any suggestions would be appreciated.
-- Cindy
TerryC - 26 Jul 2006 15:44 GMT
You are correct. I was able to make this work by converting the array to a
Tab and Newline delimited string. Thanks
> Hi =?Utf-8?B?VGVycnlD?=,
>
[quoted text clipped - 63 lines]
>
> -- Cindy