[Solved] Insert a Chart in Writer

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
tbuecki
Posts: 10
Joined: Wed May 23, 2012 4:29 pm

[Solved] Insert a Chart in Writer

Post 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
Last edited by tbuecki on Wed Aug 15, 2012 3:52 pm, edited 1 time in total.
OpenOffice 3.4 on Windows 7
User avatar
Hagar Delest
Moderator
Posts: 33701
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Insert a Chart in Writer

Post by Hagar Delest »

Old post, moved from Writer to Macro forum.
LibreOffice 25.2 on Linux Mint Debian Edition (LMDE 7 Gigi) and 25.2 portable on Windows 11.
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Insert a Chart in Writer

Post by Charlie Young »

tbuecki wrote: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
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.
Apache OpenOffice 4.1.1
Windows XP
tbuecki
Posts: 10
Joined: Wed May 23, 2012 4:29 pm

Re: Insert a Chart in Writer

Post 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

Code: Select all

Xray oEmbeded
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
OpenOffice 3.4 on Windows 7
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Insert a Chart in Writer

Post 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

Code: Select all

Xray oEmbeded
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)
Apache OpenOffice 4.1.1
Windows XP
Post Reply