Page 1 of 1
[Solved] Insert a Chart in Writer
Posted: Thu Jun 21, 2012 11:42 am
by tbuecki
Hello,
I want to create an diagram in writer with several data from a database. I have looked on
http://wiki.services.openoffice.org/wik ... readsheets, and now I'm trying to insert an diagram in writer. I have found some source-code on
http://hermione.s41.xrea.com/pukiwiki/i ... r%2FCharts - does anybody know the several CLSID for changing the chart-type? Or is there som easier way to make a chart in writerv with dynamic data?
Kind regards
Thomas
Re: Insert a Chart in Writer
Posted: Sat Jul 21, 2012 6:09 pm
by Hagar Delest
Old post, moved from Writer to Macro forum.
Re: Insert a Chart in Writer
Posted: Sun Jul 22, 2012 3:48 pm
by Charlie Young
It is not a matter of changing the CLSID; the one specified is for all such embedded charts. The chart type is changed by changing the chart diagram type in the program. The TextEmbedded Object inserted by the program in Thomas' example is the stock bar chart one gets by using Insert > Object > Chart, which the program then modifies by changing the DataArray and such, and many, many, other properties can be changed as well.
I happened to be working on a modification to my latest post in
this thread when this message was posted. In that example, I was using XTableCharts.addNewByName(), and I was not happy with that for various reasons. A better approach for a chart using a ChartDataArray instead of CellRanges is to use an OLE2Shape in Calc, and the TextEmbeddedObject in Writer.
I have a rather lengthy example written in JavaScript for inserting a chart in writer, but I'll refrain from posting it just now. It uses the same chart stuff specified by a dialog as I do in the other thread, and may not be quite appropriate here without some modifications.
Re: Insert a Chart in Writer
Posted: Thu Aug 02, 2012 12:04 pm
by tbuecki
Hello Charlie,
great, it works fine in a ods-Document. When I try to implement this in writer beginning with:
Code: Select all
sub Test
Dim objDoc as Object
Dim objDiagramme, oEmbeded as Object
Dim objDiaFlaeche as New com.sun.star.awt.Rectangle
objDoc = ThisComponent
oEmbeded = objDoc.createInstance("com.sun.star.text.TextEmbeddedObject")
oEmbeded.setPropertyValue("CLSID","12DCAE26-281F-416F-a234-c3086127382e")
Xray oEmbeded.Model
exit sub
I got a "Unknown property", athoug a
shows "Model object <error> read-only, may be void "
I will try to implement this in writer, if I have a result, I post it. Have you an idea, whats wrong?
Kind regards
Thomas
Re: Insert a Chart in Writer
Posted: Thu Aug 02, 2012 1:48 pm
by Charlie Young
tbuecki wrote:Hello Charlie,
great, it works fine in a ods-Document. When I try to implement this in writer beginning with:
Code: Select all
sub Test
Dim objDoc as Object
Dim objDiagramme, oEmbeded as Object
Dim objDiaFlaeche as New com.sun.star.awt.Rectangle
objDoc = ThisComponent
oEmbeded = objDoc.createInstance("com.sun.star.text.TextEmbeddedObject")
oEmbeded.setPropertyValue("CLSID","12DCAE26-281F-416F-a234-c3086127382e")
Xray oEmbeded.Model
exit sub
I got a "Unknown property", athoug a
shows "Model object <error> read-only, may be void "
I will try to implement this in writer, if I have a result, I post it. Have you an idea, whats wrong?
Kind regards
Thomas
The Model, and also the EmbeddedObject properties (which is effectively the same thing), are not created until the object is inserted with Text.insertTextContent. The only thing I do to the object before so inserting it (other than assign the CLSID), is give it a size and a name, neither of which is strictly necessary, but generally you'll want control of these things.
Code: Select all
oText = ThisComponent.getText()
oEmbeded.setSize(....)
oEmbeded.setName(".........")
oText.insertTextContent(oText.getEnd(),oEmbeded,True)