Использование OpenOffice как OLE


Пример чтения XLS таблички (read.vbs):

Set ServiceManager = WScript.CreateObject("com.sun.star.ServiceManager")

Set Desktop = ServiceManager.createInstance("com.sun.star.frame.Desktop")

Dim args(0)
Set args(0) = ServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
args(0).Name = "Hidden"
args(0).Value = True

Url = "file:///d:/tmp/11/test.xls"

Set Doc = Desktop.loadComponentFromURL(Url, "_blank", 0, args)

Set Sheets = Doc.getSheets()

MsgBox "SheetCount=" & Sheets.getCount()

Set Sheet = Sheets.getByIndex(0)

Set Cursor = Sheet.createCursor
Cursor.gotoEndOfUsedArea(False)
Set LastRowOfUsedArea = Cursor.RangeAddress

MsgBox "RowCount=" & LastRowOfUsedArea.EndRow
MsgBox "ColCount=" & LastRowOfUsedArea.EndColumn

Set Cell = Sheet.getCellByPosition(2, 0)

MsgBox "Cell (2,0)=" & Cell.getString()

Doc.close(0)


Пример записи XLS таблички (write.vbs):

Set ServiceManager = WScript.CreateObject("com.sun.star.ServiceManager")

Set Desktop = ServiceManager.createInstance("com.sun.star.frame.Desktop")

Dim args()

Set Doc = Desktop.LoadComponentFromURL("private:factory/scalc", "_blank", 0, args)

Set Sheets = Doc.getSheets()

Set Sheet = Sheets.getByIndex(0)

For i = 0 To 9
  Set Cell = Sheet.getCellByPosition(i, 0)
  Cell.setString("x" & i)
Next

MsgBox "ok!"

Url = "file:///d:/tmp/11/test.xls"

Redim args(1)

Set args(0) = ServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
args(0).Name = "Overwrite"
args(0).Value = True
Set args(1) = ServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
args(1).Name = "FilterName"
args(1).Value = "MS Excel 97"

Doc.storeAsURL Url, args

Doc.close(0)