2

I'm new to OpenOffice and I'm trying to port an MS Office macro over to OpenOffice Basic. I need to be able to open a Calc spreadsheet from Writer so I can dump its contents into an array in my Writer macro. The OpenOffice documentation is tough going. Thanks!

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Bob_Kruger
  • 125
  • 1
  • 4
  • 17

1 Answers1

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
Inops
  • 149
  • 6
Bob_Kruger
  • 125
  • 1
  • 4
  • 17