Print active sheet in multi sheet spreadsheet

asked 2018-06-06 14:34:31 +0200

Goc2 gravatar image

Windows 7 - LO Version 5.2.3.3 Linux - LO Version 5.3.3

Have a multi sheet spreadsheet that prints only the currently open sheet with a "button activated macro".

The two pages each have their own button and macro. The complete macros (Sheet1) and (Sheet2) are shown below.

These macros work on my Windows 7 computer. When "Sheet1" is open it only prints "Sheet1" on button click. When "Sheet2" is open it only prints "Sheet2" on button click.

The problem is when this spreadsheet is open on a Linux system it only prints Sheet1 for both "Sheet1" and "Sheet2".

 sub Sheet1
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 = "Printer"
args1(0).Value = thiscomponent.Sheets.getByName("Settings").getcellbyposition(3,12).string

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

rem ----------------------------------------------------------------------
dim args2(2) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Copies"
args2(0).Value = thiscomponent.Sheets.getByName("Settings").getCellRangeByName("D9").value
args2(1).Name = "RangeText"
args2(1).Value = "1"
args2(2).Name = "Collate"
args2(2).Value = true

dispatcher.executeDispatch(document, ".uno:Print", "", 0, args2())

rem ----------------------------------------------------------------------
    document = ThisComponent  'assigns the current document to the variable document
    Sheets = document.Sheets  'get the container of all Sheets
    Sheet = Sheets.getByName("Sheet1")   'get the sheet named Sheet1
    Controller = document.getcurrentController
    Controller.setActiveSheet(Sheet)

end sub


sub Sheet2
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 = "Printer"
args1(0).Value = thiscomponent.Sheets.getByName("Settings").getcellbyposition(3,12).string

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

rem ----------------------------------------------------------------------
dim args2(2) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Copies"
args2(0).Value = thiscomponent.Sheets.getByName("Settings").getCellRangeByName("D5").value
args2(1).Name = "RangeText"
args2(1).Value = "1"
args2(2).Name = "Collate"
args2(2).Value = true

dispatcher.executeDispatch(document, ".uno:Print", "", 0, args2())

rem ----------------------------------------------------------------------

    document = ThisComponent  'assigns the current document to the variable document
    Sheets = document.Sheets  'get the container of all Sheets
    Sheet = Sheets.getByName("Sheet2")   'get the sheet named Sheet2
    Controller = document.getcurrentController
    Controller.setActiveSheet(Sheet)


end sub
edit retag flag offensive close merge delete

Comments

Better to attach the file (empty cells containing sensitive data, or change them to show "false" data).

Xoristzatziki gravatar imageXoristzatziki ( 2018-06-07 06:57:31 +0200 )edit

The file can be found at this link. link text

Goc2 gravatar imageGoc2 ( 2018-06-08 17:05:35 +0200 )edit

Sorry, file is inaccessible by me. Please upload it here. Edit your question and find the attach symbol.

Xoristzatziki gravatar imageXoristzatziki ( 2018-06-09 06:01:18 +0200 )edit
1

Use help here to attach the file.

Xoristzatziki gravatar imageXoristzatziki ( 2018-06-09 07:20:30 +0200 )edit

The file has now been attached at the very bottom of the original question.

Goc2 gravatar imageGoc2 ( 2018-06-12 15:44:13 +0200 )edit