[英]LibreOffice Calc Macro: printing a sheet gives 'no such method or property: $(ARG1)"
我有一個電子表格,其中包含幾張紙上的行數據。 這些工作表是任意命名的(不是 sheet1 sheet2 也不是任何類似的方案)。
我需要從當前工作表的其中一行中提取一些信息(我在輸入框中給出行號),然后將此信息放在另一張工作表上以對其進行格式化,然后打印該格式化工作表,最后返回 go到我所在的初始工作表(其中一個包含數據)。
到目前為止,我已經提出了這段代碼:(我省略了行選擇和數據復制,因為它有效)
' Sheets("facture").PrintOut
Dim oDoc as Object
oDoc=ThisComponent
Dim sPrefix$ ' Prefix used to identify the print listener routines.
Dim sService$ ' Print listener service name
sPrefix="print_listener_"
sService="com.sun.star.view.XPrintJobListener"
If NOT oDoc.sheets().hasByName("facture") Then
MsgBox "Le document n'a pas de page nommée 'facture'"
Else
Dim oSheets
oSheets = oDoc.Sheets
Dim currentSheet
currentSheet = oDoc.getcurrentcontroller.activesheet
oDoc.currentController.setActiveSheet(oSheets.getByName("facture"))
oPrintListener=CreateUnoListener(sPrefix,sService)
oDoc.addPrintJobListener(oPrintListener)
'oPrintJobListnerDoc=oDoc
oDoc.Print(Array())
wait 12000
oDoc.currentController.setActiveSheet(currentSheet)
但是,當我運行它時,我的 output 表上的數據格式正確,但是 VB window 彈出“基本運行時錯誤:找不到屬性或方法:$(ARG1)”。
如果我刪除 'wait 12000' 和 'oDoc.currentController.setActiveSheet(currentSheet)' 則數據打印正確,但 Calc 保留在 output 工作表上,並且不會回到我打開的初始工作表(顯然)。
如果我只刪除“等待 12000”,則不會發生任何事情,並且不會打印數據。
有人可以幫忙嗎? 謝謝!
等待打印結束的一般原理可以表示如下
REM ***** BASIC *****
Public Statex1 As Integer ' Through this variable, the event handling procedure will notify the main program
Public oPrintJobListnerDoc As Variant
Sub PrintOutFacture()
Dim oDoc As Variant
oDoc=ThisComponent
Statex1=0
oPrintJobListnerDoc = CreateUnoListener("print_listener_", "com.sun.star.view.XPrintJobListener")
oDoc.addPrintJobListener(oPrintJobListnerDoc)
Rem ...Prepare the print - fill the cells with the desired values, format, define the print area, etc.
oDoc.Print(Array()) ' It might not be an empty array, but a whole bunch of print options!
While Statex1=0 ' 1 = Printing completed, 3 = Print canceled
Wait 100
Wend
oDoc.removePrintJobListener(oPrintJobListnerDoc)
Rem ...Post-Print Actions - Switch the sheet, close the document, or do something else
End Sub
Sub print_listener_printJobEvent(oEvent As Variant)
Statex1 = oEvent.State ' Pass the value of the State field of the oEvent to the main program through the Public variable Statex1
End Sub
Sub print_listener_disposing
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.