如何使用 VBS 管理 LibreOffice Calc 文件?

如何使用 VBS 管理 LibreOffice Calc 文件?

我正在学习 VBS 脚本,有人给了我下面的代码,它可以与 Microsoft Excel 一起使用。如何将其转换为与 LibreOffice Calc 一起使用?

Dim ObjExcel 
Call ExcelSetup("Sheet1")

Sub ExcelSetup(sheetName)
  Set objExcel = CreateObject("Excel.Application") 
  Set objwb = objExcel.Workbooks.Add 
  Set objwb = objExcel.ActiveWorkbook.Worksheets(sheetName) 

  Objwb.Name = "Sheet name for user"
  objwb.Activate 
  objExcel.Visible = True 
  objwb.Cells(1, 2).Value = "Hello world!" 
End Sub 

MsgBox "The End"

答案1

以下是改编自的脚本https://www.openoffice.org/udk/common/man/tutorial/office_automation.html

Set oSM = CreateObject("com.sun.star.ServiceManager")
Set oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
Dim arg()
Set wb = oDesk.loadComponentFromURL("private:factory/scalc", "_blank", 0, arg)
Set oSheet = wb.CurrentController.ActiveSheet
oSheet.getCellByPosition(1, 2).String = "Hello world!"
MsgBox "The End"

相关内容