微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

LibreOffice Calc 宏:打印工作表给出“没有这样的方法或属性:$(ARG1)”

如何解决LibreOffice Calc 宏:打印工作表给出“没有这样的方法或属性:$(ARG1)”

我有一个电子表格,其中包含多张纸上的多行数据。这些工作表是任意命名的(不是 sheet1 sheet2 或任何类似的方案)。

我需要从当前工作表的一行中提取一些信息(我在输入框中给出了该行的编号),然后将此信息放在另一张工作表上以对其进行格式化,然后打印该格式化工作表,然后最后回到我所在的初始工作表(其中一个包含数据)。

到目前为止我已经想出了这个代码:(我省略了行选择和数据复制,因为它有效)

 '   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)

但是,当我运行它时,输出表上的数据格式正确,但 VB 窗口弹出“BASIC 运行时错误:找不到属性方法:$(ARG1)”。

如果我删除“wait 12000”和“odoc.currentController.setActiveSheet(currentSheet)”,那么数据将正确打印,但 Calc 仍保留在输出表上,并且不会返回到我所在的初始表(显然)。

如果我只删除'wait 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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。