[Solved] setDataArray causes exception

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
ptsenter
Posts: 22
Joined: Thu Feb 21, 2008 9:02 pm

[Solved] setDataArray causes exception

Post by ptsenter »

Hi,
here a snippet from Java program:

Code: Select all

Object dataArguments[][] = new Object[1][Policy.analysisLength];
XCellRange cellRange     = sheet.getCellRangpByPosition(0, j, Policy.analysisLength - 1, j);  //I assume this is one row
XCellRangeData cellData  = (XCellRangeData)UnoRuntime.queryInterface(XCellRangeData.class, cellRange);
dataArguments            = cellData.getDataArray();         // I got correct data
cellData.setDataArray(dataArguments);                       // always fails  "com.sun.star.uno.RuntimeException"
The last statement always fails.
What are possible reasons for that?

Thank you.
Last edited by ptsenter on Tue Jun 03, 2008 10:05 pm, edited 1 time in total.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: setDataArray causes exception

Post by Villeroy »

setDataArray requires a nested list of list.
A1:C3.getDataArray() => ( (A1,B1,C1), (A2,B2,C2), (A3,B3,C3) )
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
ptsenter
Posts: 22
Joined: Thu Feb 21, 2008 9:02 pm

Re: setDataArray causes exception

Post by ptsenter »

But what does this mean in Java's terms?
getDataArray returns Object[][] which is sequence of sequence.
One would assume what's returned by getDataArray should be successfully passed to setDataArray - which is exactly what documentation claims true.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: setDataArray causes exception

Post by Villeroy »

Sorry, I don't read Java well. However, the "old forum" provides the richest source of examples.
http://www.oooforum.org/forum/viewtopic ... tdataarray
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
ptsenter
Posts: 22
Joined: Thu Feb 21, 2008 9:02 pm

Re: setDataArray causes exception

Post by ptsenter »

OK, it turned out that an error lies outside of a code I provided: a spreadsheet I tried to update with setDataArray was read-only. One might argue it's an user's error. It is.
But OpenOffice might have been smarter and throw more meaningful exception instead of generic com.sun.star.uno.RuntimeException. In this particular case, and in most Java cases, error handling routine does not even need to know what exception has been raised by Java and just propagate (raise) it upstream and I would see IIOException.
The only reason for com.sun.star.uno.RuntimeException in this case documentation provides is size mismatch, which is completely confusing.
Anyway, thank you for your help, especially CellRange, which saved my day - it sped up filling a spreadsheet by 120+ times.
Post Reply