summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2021-07-12 18:19:59 +0200
committerJean-Pierre Ledure <jp@ledure.be>2021-07-13 08:59:19 +0200
commita35b49c58519925f5b093edbc3b59180dc8a03eb (patch)
tree833b29a7d367efb27f0c95a87bfa0ced1c4f91c2 /wizards
parent02a56168ae20b575eae532d81612eeff558a7fe1 (diff)
ScriptForge - (SFDocuments) new PrintOut() method
The PrintOut() method launches the printing of a LO document to a printer previously defined by default, by the user or by the SetPrinter() method. It is applicable on any document, on a Calc sheet, a Base form document. For a Writer document specific arguments may be provided. Implemented both for Basic and Python user scripts. Change-Id: I51ce897b66d3e5624cec97a46e5eb28d9132357a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118786 Tested-by: Jean-Pierre Ledure <jp@ledure.be> Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Diffstat (limited to 'wizards')
-rw-r--r--wizards/source/scriptforge/python/scriptforge.py14
-rw-r--r--wizards/source/sfdocuments/SF_Base.xba60
-rw-r--r--wizards/source/sfdocuments/SF_Calc.xba59
-rw-r--r--wizards/source/sfdocuments/SF_Document.xba57
-rw-r--r--wizards/source/sfdocuments/SF_Writer.xba77
5 files changed, 267 insertions, 0 deletions
diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py
index 1d7bd96fa2c5..5e3b2c6c7a8c 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -1748,6 +1748,9 @@ class SFDocuments:
def CloseDocument(self, saveask = True):
return self.ExecMethod(self.vbMethod, 'CloseDocument', saveask)
+ def PrintOut(self, pages = '', copies = 1):
+ return self.ExecMethod(self.vbMethod, 'PrintOut', pages, copies)
+
def RunCommand(self, command):
return self.ExecMethod(self.vbMethod, 'RunCommand', command)
@@ -1806,6 +1809,9 @@ class SFDocuments:
def OpenFormDocument(self, formdocument, designmode = False):
return self.ExecMethod(self.vbMethod, 'OpenFormDocument', formdocument, designmode)
+ def PrintOut(self, formdocument, pages = '', copies = 1):
+ return self.ExecMethod(self.vbMethod, 'PrintOut', formdocument, pages, copies)
+
def SetPrinter(self, formdocument = '', printer = '', orientation = '', paperformat = ''):
return self.ExecMethod(self.vbMethod, 'SetPrinter', formdocument, printer, orientation, paperformat)
@@ -1945,6 +1951,9 @@ class SFDocuments:
width = ScriptForge.cstSymEmpty):
return self.ExecMethod(self.vbMethod, 'Offset', range, rows, columns, height, width)
+ def PrintOut(self, sheetname = '~', pages = '', copies = 1):
+ return self.ExecMethod(self.vbMethod, 'PrintOut', sheetname, pages, copies)
+
def RemoveSheet(self, sheetname):
return self.ExecMethod(self.vbMethod, 'RemoveSheet', sheetname)
@@ -2103,6 +2112,11 @@ class SFDocuments:
def Forms(self, form = ''):
return self.ExecMethod(self.vbMethod + self.flgArrayRet, 'Forms', form)
+ def PrintOut(self, pages = '', copies = 1, printbackground = True, printblankpages = False,
+ printevenpages = True, printoddpages = True, printimages = True):
+ return self.ExecMethod(self.vbMethod, 'PrintOut', pages, copies, printbackground, printblankpages,
+ printevenpages, printoddpages, printimages)
+
# ##############################################False##################################################################
# CreateScriptService() ###
diff --git a/wizards/source/sfdocuments/SF_Base.xba b/wizards/source/sfdocuments/SF_Base.xba
index 7ed8360c4fd0..52fc0fd768c2 100644
--- a/wizards/source/sfdocuments/SF_Base.xba
+++ b/wizards/source/sfdocuments/SF_Base.xba
@@ -404,10 +404,12 @@ Public Function Methods() As Variant
, &quot;GetDatabase&quot; _
, &quot;IsLoaded&quot; _
, &quot;OpenFormDocument&quot; _
+ , &quot;PrintOut&quot; _
, &quot;RunCommand&quot; _
, &quot;Save&quot; _
, &quot;SaveAs&quot; _
, &quot;SaveCopyAs&quot; _
+ , &quot;SetPrinter&quot; _
)
End Function &apos; SFDocuments.SF_Base.Methods
@@ -470,6 +472,64 @@ Catch:
End Function &apos; SFDocuments.SF_Base.OpenFormDocument
REM -----------------------------------------------------------------------------
+Public Function PrintOut(Optional ByVal FormDocument As Variant _
+ , Optional ByVal Pages As Variant _
+ , Optional ByVal Copies As Variant _
+ ) As Boolean
+&apos;&apos;&apos; Send the content of the given form document to the printer.
+&apos;&apos;&apos; The printer might be defined previously by default, by the user or by the SetPrinter() method
+&apos;&apos;&apos; The given form document must be open. It is activated by the method.
+&apos;&apos;&apos; Args:
+&apos;&apos;&apos; FormDocument: a valid document form name as a case-sensitive string
+&apos;&apos;&apos; Pages: the pages to print as a string, like in the user interface. Example: &quot;1-4;10;15-18&quot;. Default = all pages
+&apos;&apos;&apos; Copies: the number of copies
+&apos;&apos;&apos; Exceptions:
+&apos;&apos;&apos; FORMDEADERROR The form is not open
+&apos;&apos;&apos; Returns:
+&apos;&apos;&apos; True when successful
+&apos;&apos;&apos; Examples:
+&apos;&apos;&apos; oDoc.PrintOut(&quot;myForm&quot;, &quot;1-4;10;15-18&quot;, Copies := 2)
+
+Dim bPrint As Boolean &apos; Return value
+Dim vFormNames As Variant &apos; Array of all document form names present in the document
+Dim oFormDocument As Object &apos; com.sun.star.comp.sdb.Content
+
+Const cstThisSub = &quot;SFDocuments.Base.PrintOut&quot;
+Const cstSubArgs = &quot;FormDocument, [Pages=&quot;&quot;&quot;&quot;], [Copies=1]&quot;
+
+ If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
+ bPrint = False
+
+Check:
+ If IsMissing(Pages) Or IsEmpty(Pages) Then Pages = &quot;&quot;
+ If IsMissing(Copies) Or IsEmpty(Copies) Then Copies = 1
+
+ If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
+ If Not _IsStillAlive() Then GoTo Finally
+ &apos; Build list of available FormDocuments recursively with _CollectFormDocuments
+ If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
+ vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
+ If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormNames) Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(Pages, &quot;Pages&quot;, V_STRING) Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(Copies, &quot;Copies&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
+ End If
+ If Not IsLoaded(FormDocument) Then GoTo CatchClosed
+
+Try:
+ Set oFormDocument = _FormDocuments.getByHierarchicalName(FormDocument)
+ bPrint = [_Super].PrintOut(Pages, Copies, oFormDocument.Component)
+
+Finally:
+ PrintOut = bPrint
+ ScriptForge.SF_Utils._ExitFunction(cstThisSub)
+ Exit Function
+Catch:
+ GoTo Finally
+CatchClosed:
+ ScriptForge.SF_Exception.RaiseFatal(FORMDEADERROR, FormDocument, _FileIdent())
+End Function &apos; SFDocuments.SF_Base.PrintOut
+
+REM -----------------------------------------------------------------------------
Public Function Properties() As Variant
&apos;&apos;&apos; Return the list or properties of the Base class as an array
diff --git a/wizards/source/sfdocuments/SF_Calc.xba b/wizards/source/sfdocuments/SF_Calc.xba
index f5247088d2a2..b5a491915ceb 100644
--- a/wizards/source/sfdocuments/SF_Calc.xba
+++ b/wizards/source/sfdocuments/SF_Calc.xba
@@ -1361,6 +1361,7 @@ Public Function Methods() As Variant
, &quot;MoveRange&quot; _
, &quot;MoveSheet&quot; _
, &quot;Offset&quot; _
+ , &quot;PrintOut&quot; _
, &quot;RemoveSheet&quot; _
, &quot;RenameSheet&quot; _
, &quot;RunCommand&quot; _
@@ -1370,6 +1371,7 @@ Public Function Methods() As Variant
, &quot;SetArray&quot; _
, &quot;SetCellStyle&quot; _
, &quot;SetFormula&quot; _
+ , &quot;SetPrinter&quot; _
, &quot;SetValue&quot; _
, &quot;SortRange&quot; _
)
@@ -1554,6 +1556,63 @@ Catch:
End Function &apos; SF_Documents.SF_Calc.Offset
REM -----------------------------------------------------------------------------
+Public Function PrintOut(Optional ByVal SheetName As Variant _
+ , Optional ByVal Pages As Variant _
+ , Optional ByVal Copies As Variant _
+ ) As Boolean
+&apos;&apos;&apos; Send the content of the given sheet to the printer.
+&apos;&apos;&apos; The printer might be defined previously by default, by the user or by the SetPrinter() method
+&apos;&apos;&apos; Args:
+&apos;&apos;&apos; SheetName: the sheet to print. Default = the active sheet
+&apos;&apos;&apos; Pages: the pages to print as a string, like in the user interface. Example: &quot;1-4;10;15-18&quot;. Default = all pages
+&apos;&apos;&apos; Copies: the number of copies
+&apos;&apos;&apos; Returns:
+&apos;&apos;&apos; True when successful
+&apos;&apos;&apos; Examples:
+&apos;&apos;&apos; oDoc.PrintOut(&quot;SheetX&quot;, &quot;1-4;10;15-18&quot;, Copies := 2)
+
+Dim bPrint As Boolean &apos; Return value
+Dim oSheet As Object &apos; SheetName as a reference
+
+Const cstThisSub = &quot;SFDocuments.Calc.PrintOut&quot;
+Const cstSubArgs = &quot;[SheetName=&quot;&quot;~&quot;&quot;], [Pages=&quot;&quot;&quot;&quot;], [Copies=1]&quot;
+
+ If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
+ bPrint = False
+
+Check:
+ If IsMissing(SheetName) Or IsEmpty(SheetName) Then SheetName = &quot;&quot;
+ If IsMissing(Pages) Or IsEmpty(Pages) Then Pages = &quot;&quot;
+ If IsMissing(Copies) Or IsEmpty(Copies) Then Copies = 1
+
+ If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
+ If Not _IsStillAlive() Then GoTo Finally
+ If Not _ValidateSheet(SheetName, &quot;SheetName&quot;, , True, True) Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(Pages, &quot;Pages&quot;, V_STRING) Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(Copies, &quot;Copies&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
+ End If
+
+Try:
+ If SheetName = &quot;~&quot; Then SheetName = &quot;&quot;
+ &apos; Make given sheet active
+ If Len(SheetName) &gt; 0 Then
+ With _Component
+ Set oSheet = .getSheets.getByName(SheetName)
+ Set .CurrentController.ActiveSheet = oSheet
+ End With
+ End If
+
+ bPrint = [_Super].PrintOut(Pages, Copies, _Component)
+
+Finally:
+ PrintOut = bPrint
+ ScriptForge.SF_Utils._ExitFunction(cstThisSub)
+ Exit Function
+Catch:
+ GoTo Finally
+End Function &apos; SFDocuments.SF_Calc.PrintOut
+
+REM -----------------------------------------------------------------------------
Public Function Properties() As Variant
&apos;&apos;&apos; Return the list or properties of the Calc class as an array
diff --git a/wizards/source/sfdocuments/SF_Document.xba b/wizards/source/sfdocuments/SF_Document.xba
index 85eafb39dd84..40c39822d531 100644
--- a/wizards/source/sfdocuments/SF_Document.xba
+++ b/wizards/source/sfdocuments/SF_Document.xba
@@ -500,15 +500,72 @@ Public Function Methods() As Variant
Methods = Array( _
&quot;Activate&quot; _
, &quot;CloseDocument&quot; _
+ , &quot;PrintOut&quot; _
, &quot;RunCommand&quot; _
, &quot;Save&quot; _
, &quot;SaveAs&quot; _
, &quot;SaveCopyAs&quot; _
+ , &quot;SetPrinter&quot; _
)
End Function &apos; SFDocuments.SF_Document.Methods
REM -----------------------------------------------------------------------------
+Public Function PrintOut(Optional ByVal Pages As Variant _
+ , Optional ByVal Copies As Variant _
+ , Optional ByRef _Document As Variant _
+ ) As Boolean
+&apos;&apos;&apos; Send the content of the document to the printer.
+&apos;&apos;&apos; The printer might be defined previously by default, by the user or by the SetPrinter() method
+&apos;&apos;&apos; Args:
+&apos;&apos;&apos; Pages: the pages to print as a string, like in the user interface. Example: &quot;1-4;10;15-18&quot;. Default = all pages
+&apos;&apos;&apos; Copies: the number of copies
+&apos;&apos;&apos; _Document: undocumented argument to designate the document to print when called from a subclass
+&apos;&apos;&apos; Returns:
+&apos;&apos;&apos; True when successful
+&apos;&apos;&apos; Examples:
+&apos;&apos;&apos; oDoc.PrintOut(&quot;1-4;10;15-18&quot;, Copies := 2)
+
+Dim bPrint As Boolean &apos; Return value
+Dim vPrintGoal As Variant &apos; Array of property values
+
+Const cstThisSub = &quot;SFDocuments.Document.PrintOut&quot;
+Const cstSubArgs = &quot;[Pages=&quot;&quot;&quot;&quot;], [Copies=1]&quot;
+
+ If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
+ bPrint = False
+
+Check:
+ If IsMissing(Pages) Or IsEmpty(Pages) Then Pages = &quot;&quot;
+ If IsMissing(Copies) Or IsEmpty(Copies) Then Copies = 1
+ If IsMissing(_Document) Or IsEmpty(_Document) Or IsNull(_Document) Then Set _Document = _Component
+
+ If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
+ If Not _IsStillAlive() Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(Pages, &quot;Pages&quot;, V_STRING) Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(Copies, &quot;Copies&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
+ End If
+
+Try:
+ vPrintGoal = Array( _
+ ScriptForge.SF_Utils._MakePropertyValue(&quot;CopyCount&quot;, CInt(Copies)) _
+ , ScriptForge.SF_Utils._MakePropertyValue(&quot;Collate&quot;, True) _
+ , ScriptForge.SF_Utils._MakePropertyValue(&quot;Pages&quot;, Pages) _
+ , ScriptForge.SF_Utils._MakePropertyValue(&quot;Wait&quot;, False) _
+ )
+
+ _Document.Print(vPrintGoal)
+ bPrint = True
+
+Finally:
+ PrintOut = bPrint
+ ScriptForge.SF_Utils._ExitFunction(cstThisSub)
+ Exit Function
+Catch:
+ GoTo Finally
+End Function &apos; SFDocuments.SF_Document.PrintOut
+
+REM -----------------------------------------------------------------------------
Public Function Properties() As Variant
&apos;&apos;&apos; Return the list or properties of the Document class as an array
diff --git a/wizards/source/sfdocuments/SF_Writer.xba b/wizards/source/sfdocuments/SF_Writer.xba
index 8a821112e78a..7d839c7b5ba6 100644
--- a/wizards/source/sfdocuments/SF_Writer.xba
+++ b/wizards/source/sfdocuments/SF_Writer.xba
@@ -220,15 +220,92 @@ Public Function Methods() As Variant
&quot;Activate&quot; _
, &quot;CloseDocument&quot; _
, &quot;Forms&quot; _
+ , &quot;PrintOut&quot; _
, &quot;RunCommand&quot; _
, &quot;Save&quot; _
, &quot;SaveAs&quot; _
, &quot;SaveCopyAs&quot; _
+ , &quot;SetPrinter&quot; _
)
End Function &apos; SFDocuments.SF_Writer.Methods
REM -----------------------------------------------------------------------------
+Public Function PrintOut(Optional ByVal Pages As Variant _
+ , Optional ByVal Copies As Variant _
+ , Optional ByVal PrintBackground As Variant _
+ , Optional ByVal PrintBlankPages As Variant _
+ , Optional ByVal PrintEvenPages As Variant _
+ , Optional ByVal PrintOddPages As Variant _
+ , Optional ByVal PrintImages As Variant _
+ ) As Boolean
+&apos;&apos;&apos; Send the content of the document to the printer.
+&apos;&apos;&apos; The printer might be defined previously by default, by the user or by the SetPrinter() method
+&apos;&apos;&apos; Args:
+&apos;&apos;&apos; Pages: the pages to print as a string, like in the user interface. Example: &quot;1-4;10;15-18&quot;. Default = all pages
+&apos;&apos;&apos; Copies: the number of copies
+&apos;&apos;&apos; PrintBackground: print the background image when True (default)
+&apos;&apos;&apos; PrintBlankPages: when False (default), omit empty pages
+&apos;&apos;&apos; PrintEvenPages: print the left pages when True (default)
+&apos;&apos;&apos; PrintOddPages: print the right pages when True (default)
+&apos;&apos;&apos; PrintImages: print the graphic objects when True (default)
+&apos;&apos;&apos; Returns:
+&apos;&apos;&apos; True when successful
+&apos;&apos;&apos; Examples:
+&apos;&apos;&apos; oDoc.PrintOut(&quot;1-4;10;15-18&quot;, Copies := 2, PrintImages := False)
+
+Dim bPrint As Boolean &apos; Return value
+Dim vPrintOptions As Variant &apos; com.sun.star.text.DocumentSettings
+
+Const cstThisSub = &quot;SFDocuments.Writer.PrintOut&quot;
+Const cstSubArgs = &quot;[Pages=&quot;&quot;&quot;&quot;], [Copies=1], [PrintBackground=True], [PrintBlankPages=False], [PrintEvenPages=True]&quot; _
+ &amp; &quot;, [PrintOddPages=True], [PrintImages=True]&quot;
+
+ If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
+ bPrint = False
+
+Check:
+ If IsMissing(Pages) Or IsEmpty(Pages) Then Pages = &quot;&quot;
+ If IsMissing(Copies) Or IsEmpty(Copies) Then Copies = 1
+ If IsMissing(PrintBackground) Or IsEmpty(PrintBackground) Then PrintBackground = True
+ If IsMissing(PrintBlankPages) Or IsEmpty(PrintBlankPages) Then PrintBlankPages = False
+ If IsMissing(PrintEvenPages) Or IsEmpty(PrintEvenPages) Then PrintEvenPages = True
+ If IsMissing(PrintOddPages) Or IsEmpty(PrintOddPages) Then PrintOddPages = True
+ If IsMissing(PrintImages) Or IsEmpty(PrintImages) Then PrintImages = True
+
+ If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
+ If Not _IsStillAlive() Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(Pages, &quot;Pages&quot;, V_STRING) Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(Copies, &quot;Copies&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(PrintBackground, &quot;PrintBackground&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(PrintBlankPages, &quot;PrintBlankPages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(PrintEvenPages, &quot;PrintEvenPages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(PrintOddPages, &quot;PrintOddPages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(PrintImages, &quot;PrintImages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
+ End If
+
+Try:
+ vPrintOptions = _Component.createInstance(&quot;com.sun.star.text.DocumentSettings&quot;)
+ With vPrintOptions
+ .PrintPageBackground = PrintBackground
+ .PrintEmptyPages = PrintBlankPages
+ .PrintLeftPages = PrintEvenPages
+ .PrintRightPages = PrintOddPages
+ .PrintGraphics = PrintImages
+ .PrintDrawings = PrintImages
+ End With
+
+ bPrint = [_Super].PrintOut(Pages, Copies, _Component)
+
+Finally:
+ PrintOut = bPrint
+ ScriptForge.SF_Utils._ExitFunction(cstThisSub)
+ Exit Function
+Catch:
+ GoTo Finally
+End Function &apos; SFDocuments.SF_Writer.PrintOut
+
+REM -----------------------------------------------------------------------------
Public Function Properties() As Variant
&apos;&apos;&apos; Return the list or properties of the Writer class as an array