Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / July 2006

Tip: Looking for answers? Try searching our database.

Need help with Paste method in Microsoft.Office.Interop.Graph

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TerryC - 20 Jul 2006 17:30 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.