Andrew Douglas Pitonyak wrote:
Craig Johnson wrote:
Andrew Douglas Pitonyak wrote:
Craig Johnson wrote:

Hi folks! Just joined the [email protected] mailing list.
[snip]
Anyone know how to access spreadsheet chart data ranges from a macro?

Depends on what you need or desire to do...

Hi Andrew,

I hope you'll excuse me for bothering you directly with this. I've tried posting on the [email protected] alias but found it to be mostly off-topic rants and/or discussions that have little or nothing to do with using openoffice. I'm getting ready to file what I think is a bug at the api.openoffice.org site but that too seems to be a non-trival task.

But you did NOT email me directly, you emailed this to [email protected] :-)

I started composing my email with the intent to send directly to you but as I
was getting ready to change the To address I thought maybe it would be good for people on this alias to read what impressions were left with a newcomer and all the posts that had *NOTHING* to do with using Openoffice.

Do you remember replying to my question above? You were really the only one who gave any useful feedback! I've recently purchased a copy of your OOME book too and have found it quite useful.

But alas, no coverage of charts :-(

I had never written a staroffice macro until ~ 3 weeks ago. For a complete newcomer like me I found you book to be an invaluable reference.

Is it time for a second edition? 8^)

The problem I'm facing now has to do with the chart getRanges and setRanges routines you pointed out in your reply to me. I'm having some difficulty understanding why they do not seem to be working for me and have come to a conclusion that it may actually be a bug (or bugs) in the openoffice code itself.

To illustrate my problem(s) I have tried to encapsulate them in a spreadsheet doc with macros that "test" things. I am hoping to find an expert user to review what I am facing and give me some feedback as to whether I'm doing something wrong or have really encountered an openoffice bug.

The attached spreadsheet doc contains the necessary data and instructions.
I would greatly appreciate any feedback you may be able to provide.

Eagerly awaiting your response,
Craig Johnson
Very interesting....

First, let me say that charts are in a strong state of change at the moment, and I have had trouble understanding them. That said, you need

Any pointers to where one might find info about known chart problems and work arounds? Or what's changing and when it will be available?

From my perspective as a newcomer understanding anything about OpenOffice and particularly access to things via macros has been troublesome.

to get the embedded object and look at that. For example:

Sub DisplayData()
   CR = Chr$(13)
   SPC = " "

   Dim Sheet as Object
   Sheet = getNamedSheet("Sheet1")

   Dim Charts as Object
   Dim Chart as Object

   Charts = Sheet.getCharts()
   Chart = Charts.getByIndex(0)
   ChartRanges = Chart.getRanges()
   Dim x, i%, j%, y, s$
   x = Chart.getEmbeddedObject().getData().getData()
   For i = LBound(x) To UBound(x)
     y = x(i)
     For j = LBound(y) To UBound(y)
       s = s & y(j) & "  "
     Next
     s = s & CHR$(10)
   Next
   MsgBox s
End Sub

The reason the lower bound on the other is -1, is because calling getRanges returns an empty array. This may be because of the chart type, but that is a wild guess.

Yes, -1 indicates an empty array but it should *not* be empty as
Format-Data Ranges shows there is a valid chart range.

My example only dealt with one chart type but I have seen this on several different chart types (e.g. bars, stacked bars, stacked bars with lines).

What I have learned since yesterday is that if I select the chart and look at Format->Data Ranges through the GUI then do the Chart.getRanges I get an array with the expected elements in it. In fact all that's really necessary is to select/deselect the chart in the GUI and the getRanges works as expected.

Do you know of a way to do a select/deselect of a chart from a macro?

The second problem is that after updating the ranges with setRanges to add a new row the X-axis tick labeling is incorrect and if you save, exit and re-open the doc the chart range displayed by Format->Data Ranges is incorrect.


The embedded object supports the com.sun.star.chart2.ChartDocument service.

You want to see the ranges?

   x = Chart.getEmbeddedObject().getUsedRangeRepresentations()
   MsgBox Join(x, CHR$(10))

I did find some old code here, that may be of interest

http://lxr.go-oo.org/source/graphics/chart2/qa/TestCaseOldAPI.java

Thanks for your timely reply and the additional examples and info!

What is your opinion on filing this as an issue at the api.openoffice.org site? (at least I think that's where bugs should be filed)

Craig




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to