Lihong

I have a PowerPoint 2007 AddIn project. In the project, a chart is added dynamically. I would like to convert the added "Shape" to type "Chart", and so I could access the datasheet behind the added chart, because I could not find a way to access data behind a "Shape" object. However, it seems shape interface cannot be converted into chart interface. See below:


Code Snippet

Dim oTestShape As Microsoft.Office.Interop.PowerPoint.Shape

oTestShape = oChartSlide.Shapes.AddChart() 'Add a PowerPoint chart

If oTestShape.HasChart Then

oTestShape.Select()

Dim oChart As Microsoft.Office.Interop.Graph.Chart

oChart = CType(oTestShape, Microsoft.Office.Interop.Graph.Chart) 'Error

Dim oSheet1 As Object = oChart.Application.DataSheet

End If

Error: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Graph.Chart'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208FB-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Am I doing something wrong Or there is no way to convert a "shape" (which I know is a chart) to "chart"

Thank you,



Re: Visual Studio Tools for Office Convert Type "Shape" To "Chart"

Cindy Meister

Hi Lihong

To answer your question, then answer is NO, it is not possible to convert a Shape to a Chart.

To address your problem: The Office 2007 object model does not provide an automation interface for the new Charting engine when objects are embedded in other files. Only with Excel can you directly automate a chart in Office 2007.

What is possible is to create and work with the older charting engine, through MS Graph or through Excel. In Office, this is done by using the OLE Automation interface of the Shape. I've never tried doing this in PowerPoint, only in Word, so you may want to go to a PowerPoint newsgroup for details - the dev regulars in that group will know how.

In Word, it would look something like this:

Dim shp as Word.Shape

Dim of as Word.OLEFormat

Dim chart as Graph.Chart

Dim appGraph as Graph.application

Set shp = ActiveDocument.Shapes(1)

Set of = shp.OLEFormat

Set chart = of.Object 'In C# you'll need to do a type conversion on this object

of.Activate 'You can also use DoVerb method

Set appGraph = chart.Application

OLEFormat provides the OLE interop of an OLE object, letting you assign an object to it. Activate (or DoVerb) access the OLE Server interface. When you're done with MS Graph, you'll probably want to exit the Graph application window so that the user sees the graph as part of the document (rather than seeing the Graph UI):

appGraph.Quit

Set chart = nothing

Set appGraph = Nothing






Re: Visual Studio Tools for Office Convert Type "Shape" To "Chart"

Lihong

Hello Cindy,

Thank you very much for your reply.

I know this is a long shot, but since you have a very good knowledge about what¡¯s doable and what¡¯s not in Office 2007, I hope you might know the answer of the question I¡¯m about to ask.

I did manage to insert an object with type "Microsoft Office Excel Chart" on to a presentation in PowerPoint 2007, and also manage to modify the data behind the chart programmatically.

However, in PowerPoint 2007, every time an inserted object with type ¡°Microsoft Office Excel Chart" is double-clicked on; a warning message always pops up:

"To edit this chart using the new features available in the 2007 Microsoft Office system, you must first convert it to the 2007 Office system format.

Do you want to convert this chart to the new format "

Obviously I would not like the end user to see this message every time my chart is been double clicked, but I could not find a way to disable this message. That¡¯s why I was looking for alternative way (insert a normal chart, and try to access the data).

I also noticed in Word 2007, when an inserted object is double clicked on, there is no such a pop-up.

Would you please shine some light on how to disable the pop-up in PowerPoint 2007

Thank you!

PS: I¡¯ve asked the question in PowerPoint newsgroup, but no one has answered it.





Re: Visual Studio Tools for Office Convert Type "Shape" To "Chart"

Cindy Meister

Since all support in the newsgroups (and many in the forums) is volunteer, you may have to wait a few days for an answer.

The alternate method would be to manipulate the Open XML file format directly, creating the chart in the closed pptx file. You should be able to find information on OpenXMLDeveloper.org.

The Office 2007 OpenXML file formats are a zipped package of xml files that define the "document". The chart could be inserted in one of these xml "parts" and manipulated there. No need to automate the Powerpoint application at all.






Re: Visual Studio Tools for Office Convert Type "Shape" To "Chart"

Alexander Weinhard

The code provided does not work neither in Word nor in Powerpoint.

shp.OLEFormat.Object does no longer exist.

Until now, nobody could explain me why.

I guess, the Office developpers did not have enough time to completely implement all necessary functions because the big bosses have again made big promisses, the developpers could not keep...

I hope for SP1 to bring back some of the missing functions.





Re: Visual Studio Tools for Office Convert Type "Shape" To "Chart"

Cindy Meister

Alexander Weinhard wrote:

The code provided does not work neither in Word nor in Powerpoint.

shp.OLEFormat.Object does no longer exist.

Until now, nobody could explain me why.

I guess, the Office developpers did not have enough time to completely implement all necessary functions because the big bosses have again made big promisses, the developpers could not keep...

I hope for SP1 to bring back some of the missing functions.

Hi Alexander

I can't speak for Powerpoint, but the OLEFormat.Object properties certainly do still exist in Word. They may not be applicable to whatever you're trying to do. That we can't judge without more information.