[Calc, Python] Print selected sheets and ranges

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

[Calc, Python] Print selected sheets and ranges

Post by Villeroy »

2016-06-27: Credits to Andrew Davison, the author of “Java LibreOffice Programming” (JLOP) who pointed me to a viable solution which is able to print selected sheets. This is not a solution for selected ranges yet. See attached spreadsheet document.
The Basic code specifies selected sheets by an array of indices, a boolean constant if the output should be printed to file or printer device together with a file name and a printer name for the respective output.

Code: Select all

REM we are going to print the first and third sheet:
aSheetNums = Array(0, 2)

REM Print to file
Const bPrintToFile = True
sOutFile = ThisComponent.URL & ".pdf"

REM if not to file, specify printer name
Const cPrinterName = "PDF"
Attachments
PrintSheets.ods
3 sheets and a macro to print sheet #1 and sheet #2 only.
(30.71 KiB) Downloaded 511 times
Last edited by Villeroy on Mon Jun 27, 2016 11:25 pm, edited 4 times in total.
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
User avatar
RichieRH
Posts: 36
Joined: Sun Oct 19, 2014 6:16 pm

Re: [Calc, Python] Print selected sheets and ranges

Post by RichieRH »

Nice.........Tks
Debian 8 Jessie
Linux Mint 17.3 XFCE
Country : Indonesia
Learning is a need
User avatar
RichieRH
Posts: 36
Joined: Sun Oct 19, 2014 6:16 pm

Re: [Calc, Python] Print selected sheets and ranges

Post by RichieRH »

How do I used it?Any examples would be appreciate ...
Debian 8 Jessie
Linux Mint 17.3 XFCE
Country : Indonesia
Learning is a need
Post Reply