Ask Your Question
0

I need help exporting a chart

asked 2018-12-01 06:11:50 +0100

Todd2 gravatar image

updated 2018-12-01 16:09:08 +0100

erAck gravatar image

Hi all,

This does export something. A down arrow, which is not on the chart, but does occur on the table to its left.

This chart in question appears on the second sheet (starting counting from 1).

What am I doing wrong?

Many thanks, -T

Sub ExportChart( ChartName As String )
   Dim MsgRtn     as Integer
   Dim shape
   Dim gef
   Dim args1(1) as new com.sun.star.beans.PropertyValue
   Dim args2(1) as new com.sun.star.beans.PropertyValue

   dim document   as object
   dim dispatcher as object

   ' change to the Weight & Balance sheet
   document   = ThisComponent.CurrentController.Frame
   dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
   args1(0).Name = "Nr"
   args1(0).Value = 2
   dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args1())

   shape = ThisComponent.getSheets().getByIndex(0).getDrawPage().getByIndex(0)
   args2(0).Name = "URL"
   ' args2(0).Value = "file:///home/asuka/Downloads/foo.png"
   args2(0).Value = "file:///" + ChartName
   args2(0).Value = Replace( args2(0).Value, "\", "/" )
  '  MsgRtn = MsgBox( args2(0).Value, 0, "ExportChart" )

   args2(1).Name = "MimeType"
   args2(1).Value = "image/png"

   gef = CreateUnoService("com.sun.star.drawing.GraphicExportFilter")
   gef.setSourceDocument(shape)
   gef.filter(args2)
End Sub
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2018-12-08 05:58:10 +0100

Todd2 gravatar image

Got it figured out. It is working beautifully. Thank you for all the help!

Sub ExportChart( ChartName As String )
   Dim MsgRtn     as Integer
   Dim shape
   Dim gef
   Dim args1(1) as new com.sun.star.beans.PropertyValue
   Dim args2(1) as new com.sun.star.beans.PropertyValue

   dim document   as object
   dim dispatcher as object

   ' change to the Weight & Balance sheet and address the weights and balance table

   shape = ThisComponent.getSheets().getByIndex(1).getDrawPage().getByIndex("WeightAndBalanceChart")
   '                                                            |                                              ^---  Name of Chart
   '                                                            ^--- 0 = sheet zero, 1= sheet1 etc, regardless if you have renamed them
   '
   args2(0).Name = "URL"
   ' args2(0).Value = "file:///home/asuka/Downloads/foo.png"
   args2(0).Value = "file:///" + ChartName
   args2(0).Value = Replace( args2(0).Value, "\", "/" )
  '  MsgRtn = MsgBox( args2(0).Value, 0, "ExportChart" )

   args2(1).Name = "MimeType"
   args2(1).Value = "image/png"

   gef = CreateUnoService("com.sun.star.drawing.GraphicExportFilter")
   gef.setSourceDocument(shape)
   gef.filter(args2)
End Sub
edit flag offensive delete link more
0

answered 2018-12-01 06:41:26 +0100

Ratslinger gravatar image

You're looking at the wrong sheet for one. This was basically answered by @Mike Kaganski in a comment on this post -> "shape" throws and error

Your code says first sheet & question says second sheet. Also, if you have more than one object on the Draw Page, you need to determine by code (a name is usually best) which object you need to retrieve and not just an arbitrary index number.

edit flag offensive delete link more

Comments

How? Where are my mistakes?

Todd2 gravatar imageTodd2 ( 2018-12-01 07:17:50 +0100 )edit

ThisComponent.getSheets().getByIndex(0) is the first sheet, that should be ThisComponent.getSheets().getByIndex(1)

erAck gravatar imageerAck ( 2018-12-01 16:05:45 +0100 )edit

Additionally, because you have (according to the question) more than one shape on the sheet. The index of the shape is in question:

shape = ThisComponent.getSheets().getByIndex(0).getDrawPage().getByIndex(???)

From DrawPage you can obtain a count of items on the sheet, loop through the items and check each name for the desired object.

Ratslinger gravatar imageRatslinger ( 2018-12-01 16:22:32 +0100 )edit

Charts do automatically get assigned a name but you can also give it your own name. See this post -> Is it possible in calc to name a chart...

Ratslinger gravatar imageRatslinger ( 2018-12-01 17:50:30 +0100 )edit

Is there some property that I an ask the chart what its name is?

Todd2 gravatar imageTodd2 ( 2018-12-02 01:18:39 +0100 )edit

Since you can have many charts on a sheet, how do you know what chart name to retrieve? To get access to charts, get wanted sheet; then getChart() (also from here you can getCount() for index loop); then getByIndex(index number); then getName().

Best to know the name of the chart and place in the macro for comparison on DrawPage.

Ratslinger gravatar imageRatslinger ( 2018-12-02 03:32:40 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-12-01 06:11:50 +0100

Seen: 37 times

Last updated: Dec 08