[Solved] Print error using Calc as report

Getting your data onto paper - or the web - Discussing the reports features of Base
Post Reply
zeke99
Posts: 24
Joined: Fri Jun 29, 2012 4:05 pm

[Solved] Print error using Calc as report

Post by zeke99 »

Since ORB hangs frequently I test other ways to get reports from base. One way is to use calc as report-engine.
There is no problem to open a calc sheet but when I try to print it I get following error:

Basic run-time error
An exception occured
Type: com.sun.star.lang.IllegalArgumentException
Message: cannot coerce argument type during coreflection call!

Tested to ways, neither working:

Code: Select all

Sub TestFunktion (Event as object)

Dim printopts as object
dim dispatcher as object
Dim oHidden(0) As New com.sun.star.beans.PropertyValue
oHidden(0).Name = "Hidden"
oHidden(0).Value = FALSE 
oDBDoc = StarDesktop.loadComponentFromURL("file:///home/prm/Affarssystem/Exempel/TestKalkyl.ods", "_blank", 0, oHidden())

REM First test - not working
'oDBDoc.print(printopts)


REM Second test - not working either
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(oDBDoc, ".uno:PrintDefault", "", 0, Array())

xray oDBDoc
msgbox " "

'oDBDoc.dispose()

end sub
Anyone know how to get the print command working?
Last edited by zeke99 on Sun Mar 03, 2013 3:14 pm, edited 1 time in total.
OpenOffice 4.1 LinuxMint 17
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Print error using Calc as report

Post by RPG »

Hello

The code is a recorded macro. Look to the next line

Code: Select all

document   = ThisComponent.CurrentController.Frame

Code: Select all

sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:PrintDefault", "", 0, Array())


end sub
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Print error using Calc as report

Post by B Marcelly »

Hi,
A correct API code:

Code: Select all

Dim printopts(0) As New com.sun.star.beans.PropertyValue
Dim oHidden(0) As New com.sun.star.beans.PropertyValue
oHidden(0).Name = "Hidden"
oHidden(0).Value = FALSE ' or True
oDBDoc = StarDesktop.loadComponentFromURL("file:///home/prm/Affarssystem/Exempel/TestKalkyl.ods", "_blank", 0, oHidden())
printopts(0).Name = "Wait"
printopts(0).Value = True ' necessary if you want to close just after
oDBDoc.print(printopts)
oDBDoc.close(True)
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
zeke99
Posts: 24
Joined: Fri Jun 29, 2012 4:05 pm

Re: Print error using Calc as report

Post by zeke99 »

Sweet! Works like a charm.
It's so damn hard to find info about these options neccesary. Countless hours spent with xray and trial/error.

Thanks a lot Marcelly. Saved me a couple of hours tonight.
Zeke
OpenOffice 4.1 LinuxMint 17
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Print error using Calc as report

Post by Villeroy »

This is how I do it:
The [Print ...] button on a form (just set the Action and URL properties) opens the report spreadsheet which runs a most trivial on-open macro to update all import ranges and pivot tables.

My report spreadsheets contain more than one report sheet. Some of them have auto-filter buttons in the header row. For any user it is very easy to select the right sheet, apply some auto-filter to get a smaller, more relevant report and print the active sheet.

Who needs one-click solutions if things can be controlled so easily?
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
Post Reply