How to print several Calc sheets via a macro

The Application Programming Interface and the OASIS Open Document Format

How to print several Calc sheets via a macro

Postby yesman » Thu Apr 07, 2011 5:18 pm

Hello everyone

I am building a little application with basic. ( I am brand new on the programming leisure) I wish to write a little macro under Calc to select 5 sheets and to print them. Does anyone have a example to share ? Unfortunately all the examples I got, are only for one sheet.

Thanks for helping
I am using Ubuntu 10.10 with OOo 3.2.1
yesman
 
Posts: 2
Joined: Thu Apr 07, 2011 5:00 pm

Re: How to print several Calc sheets via a macro

Postby andyroberts1234 » Thu Apr 07, 2011 5:23 pm

Perhaps you could put your example down and we could suggest how to edit it?
Andy

OOO 3.3.0 / Windows 7 64-bit
andyroberts1234
 
Posts: 75
Joined: Fri Feb 11, 2011 2:29 pm

Re: How to print several Calc sheets via a macro

Postby Zizi64 » Thu Apr 07, 2011 5:42 pm

Hi,

Here is one of the possible solutions:

Code: Select all   Expand viewCollapse view
Sub PrintShets
aSheets = Array(1, 3)                   '... , .5, 6,...etc
   For i=0 to uBound(aSheets)
      JumpToSheet(aSheets(i))
      PrintActiveSheet()      'it is the your print routine
   next i
end sub

sub JumpToSheet(SheetNumber)

' Recorded by MacroRecorder, but edited (modified) manually.

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 ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Nr"
args1(0).Value = SheetNumber    ' It is the modified parameter

dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args1())


end sub
Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.0; AOO4.1.6
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 8771
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: How to print several Calc sheets via a macro

Postby yesman » Thu Apr 07, 2011 6:05 pm

Dear all

Thanks for the answers. I will try the code tonight and get back to you, but it looks great and seems to fit

Thanks

-----------------------
Unfortunately this does not work on my computer I will continue my queries.

Thanks anyway

---------------------------------------------------------------------------------------------------------------------------
Hello again


I was thinking to select first the sheets and print them afterward.

Here is the code that I tried

Sub ActiveSheehts


myDocument = ThisComponent
mySheets =myDocument.Sheets

AllTheSheets = mySheets.getByIndex(0,2)
monDocument.currentController.activeSheet = AllTheSheets


end Sub


When running this code there is no warning but this code doesn't work as I want, because it does activate the sheet with the first index only. :cry:

Thanks for reading
I am using Ubuntu 10.10 with OOo 3.2.1
yesman
 
Posts: 2
Joined: Thu Apr 07, 2011 5:00 pm


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 2 guests