I am trying to feed a spreadsheet in Open Office using Visual Basic.net 2008, I am using the programming below, but this one giving several errors, can someone help me, thanks ..
Code: Select all
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oSheet As Object
Dim oSM 'Root object for accessing OpenOffice from VB
Dim oDesk, oDoc As Object 'First objects from the API
Dim arg() 'Ignore it for the moment !
'Instanciate OOo : this line is mandatory with VB for OOo API
oSM = CreateObject("com.sun.star.ServiceManager")
'Create the first and most important service
oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
'Open an existing doc (pay attention to the syntax for first argument)
oDoc = oDesk.loadComponentFromURL("file:///C:\Users\Supervisor\Desktop\testeopen\1\as.ods", "_blank", 0, arg())
'oDoc = oDesk.loadComponentFromURL("file:///C:\Users\PikachU\Desktop\Importar\as.ods", "_blank", 0, )
oSheet = oDoc.getSheets().getByIndex(0) 'seleciona primeira planilha
Call oSheet.getCellByPosition(3, 1).SetValue(111) 'seta valor col,linha
Call oSheet.getCellByPosition(3, 2).SetValue(222) 'seta valor col,linha
Call oSheet.getCellByPosition(3, 3).SetString("Marcos") 'seta valor da celular do tipo string
Call oSheet.getCellByPosition(3, 5).SetFormula("=SUM(D2:D4)") 'seta celula do tipo formula
'Save the doc
'Call oDoc.storeToURL("file:///C:\Users\Supervisor\Desktop\testeopen\\as.ods")
Call oDoc.storeToURL("file:///C:\Users\PikachU\Desktop\Importar\as.ods", arg())
oDoc.Close(True)
oDoc = Nothing
MsgBox("ok")
End Sub
End Class