Hi all,

I have some predefined charts in the excel that are generated using VBA code.I want to write a C# program to select those charts and write it to word document seperately.



Re: Visual Studio Tools for Office How to get the charts in the Excel sheet and write it to word document

Cindy Meister

Since this isn't a VSTO question, the better place to ask would be the office.developer.automation newsgroup. If you do a Google Groups search on that group and other office.developer groups you should find a few discussions about inserting/creating charts in Word.

To give you a quick overview: Charts can be embedded in Word either as OLE objects (with or without a link to the Excel chart) or as static graphical objects. The latter require fewer resources: both document size and document loading time will be significantly lower with a graphic.

The are two basic approaches, from the end-user point of view, to insert an existing chart. One is to copy in Excel and paste in to Word. The other is to use the Insert/Object/From File command. As a developer, you want to avoid going over the clipboard, which means you should first look at inserting the the object. Record that in a macro to get the basic syntax that you then "translate" to C#.

A slightly different approach, that I find faster and more manageable than InsertObject is to create the field code Word uses to maintain a link to the Excel object. I can then unlink the field if a static object is required.

You should find more detailed discussions with some code samples in the office.developer set of newsgroups.