[VB.NET] Create and save a Calc file

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Machine Head
Posts: 1
Joined: Tue Sep 25, 2018 10:10 pm

[VB.NET] Create and save a Calc file

Post by Machine Head »

Hi
I work on visual studio in vb.net language.
I want to create and save automaticaly a calc file. I use the tool " VB.NET OOo" that you could find on this website http://berma.pagesperso-orange.fr/
The beginning of my code is working until the save process. I try to find the solution during hours but nothing works
This is my code

Code: Select all

Sub Test
ConnectOpenOffice()
Dim myDoc As Object
myDoc = StarDesktop.loadComponentFromURL("private:factory/scalc", "_hidden", 0, dummyArray)

Url = ConvertToURL("C:\test.ods")

Dim arg(0) As Object
arg(0) = MakePropertyValue("Overwrite", True)

myDoc.storeAsURL(Url, arg)
myDoc.close(True)
End Sub
The used functions "VB.NET OOo " are below (I don't change the code)

Code: Select all

Sub ConnectOpenOffice()
    If IsOpenOfficeConnected() Then Exit Sub
    Try
      OpenOffice = CreateObject("com.sun.star.ServiceManager")
    Catch
      OpenOffice = Nothing
    End Try
    If isNullEmpty(OpenOffice) Then
      Err.Raise(vbObjectError + OOoErrorN, "OpenOffice", OOo_connectKO)
    Else
      StarDesktop = CreateUnoService("com.sun.star.frame.Desktop")
      OOoIntrospection = CreateUnoService("com.sun.star.beans.Introspection")
      OOoDisp = CreateUnoService("com.sun.star.frame.DispatchHelper")
      OOoTypeDescrMngr = OpenOffice.DefaultContext.getValueByName("/singletons/com.sun.star.reflection.theTypeDescriptionManager")
    End If
  End Sub

Function dummyArray() As Object
        ' cree un tableau vide, pour une liste vide 
        ' creates an empty array for an empty list
        Dim Result(-1) As Object
        dummyArray = Result
    End Function


  Function MakePropertyValue(ByVal PropName As String, ByVal PropValue As Object) As Object
        ' equivalent de la fonction de Danny Brewer
        ' equivalent to Danny Brewer's function
        Dim Result As Object

        Result = OpenOffice.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
 
        Result.Name = PropName
        Result.Value = PropValue
        MakePropertyValue = Result
    End Function

The error is on the line "storeAsURL" and it is "com.sun.star.task.ErrorCodeIOException"
Please, can you help me. Thank you in advance. Regards :super:
OpenOffice 4.1 On Windows 10
Post Reply