从Writer宏打开OpenOffice电子表格

时间:2010-11-09 19:53:20

标签: macros openoffice.org openoffice-basic

我是OpenOffice的新手,我正在尝试将MS Office宏移植到OpenOffice Basic。我需要能够从Writer打开一个Calc电子表格,这样我就可以将其内容转储到我的Writer宏中的数组中。 OpenOffice文档很难实现。谢谢!

1 个答案:

答案 0 :(得分:2)

Dim oSM 
Dim oDesk 

'Instantiate OOo
Set oSM = CreateObject("com.sun.star.ServiceManager")
'Create the services
Set oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
Set oCalc = oSM.createInstance("com.sun.star.sheet.SpreadsheetDocument")

Dim strVar(4) As String
Dim iRow As Integer
Dim iColumn As Integer
Dim strEnd As String
Dim Cell as object
Dim CalcDoc
CalcDoc = oDesk.loadComponentFromURL("file:///c:/<path>", "_blank", 0, Array())
Dim Sheet
Sheet = CalcDoc.Sheets.getByName("Sheet1")

iRow = 0
Do While strEnd <> "end"
    For iColumn = 0 To 4
     Cell = Sheet.getCellByPosition(iColumn, iRow)
     strValue = Cell.String
        strVar(iColumn) = strValue
    Next
 'first cell contains "end" at end of spreadsheet
 strEnd = Sheet.getCellByPosition(0, iRow).String
 'Do something HERE with strValue row values, like use them in a search
 iRow = iRow + 1
Loop