BASIC+Calc : Incomplete result of continuous printing

'MsgBox "Print it now ?"
		PrintSelectedArea("Sheet1",0, 0, 6, 39)
'MsgBox "Page of k = " & k & " was printed.",,"k = 0 to 5"

From the attached files if I pause before or after printing, the result is correct.

But without pausing, the result is incomplete.

MsgBox "Print it now ?"
		PrintSelectedArea("Sheet1",0, 0, 6, 39)
MsgBox "Page of k = " & k & " was printed.",,"k = 0 to 5"

How can I replace manually pausing or do I have more codes to replace manually pausing ?

TestErrorOfContinuousPrinting_PauseBeforeAndAfterPrint.ods (54.3 KB)

TestErrorOfContinuousPrinting_NoPauseBeforeOrAfterPrint.ods (54.6 KB)

Ubuntu:
22.04 LTS
LibreOffice:
Version: 7.3.3.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 4; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Ubuntu package version: 1:7.3.3-0ubuntu0.22.04.1
Calc: threaded

Please see the description of the Wait property.
Fragment:

Dim props(0) As New com.sun.star.beans.PropertyValue
'
'  your code
'
props(0).Name="Wait"
props(0).Value=True
oDoc.Print(props)
2 Likes
Sub PrintSelectedArea (sSht$, nStC&, nStR&, nEndC&, nEndR&)
	Dim selArea(0) as new com.sun.star.table.CellRangeAddress
	Dim oDoc as object
	Dim oSheet as object
	Dim oSheets
	Dim props(0) As New com.sun.star.beans.PropertyValue ' #1
	Dim i&
	oDoc = Thiscomponent
	oSheets = ThisComponent.Sheets
	For i = 0 to oSheets.getCount() - 1
		oSheet = ThisComponent.Sheets.getByIndex(i)
		oSheet.setPrintareas(array())
	Next
	selArea(0).StartColumn = nStC
	selArea(0).StartRow = nStR
	selArea(0).EndColumn = nEndC
	selArea(0).EndRow = nEndR
	oSheet=ThisComponent.Sheets.getByName(sSht)
	oSheet.setPrintareas(selArea())
'	oDoc.Print(Array()) ' #5
	props(0).Name="Wait" ' #2
	props(0).Value=True ' #3
	oDoc.Print(props) ' #4
End Sub

I added #1, #2, #3, #4 and canceled #5. The result is complete. Does oDoc.Print(props) work instead of oDoc.Print(Array()) ?

The Print method has one parameter - an array of properties. Possible property names are given in the PrintOptions service description. In your original example, an empty array is passed as a parameter to the Print method, which means that all print properties are defined by default.
The LO documentation warns about the Wait property:

Using of this property with TRUE as value is highly recommended. Otherwise following actions (as e.g. closing the corresponding model) can fail.

2 Likes