Open Office OleObject trouble

Hello, I have to use open office automation in xojo, starting from a few examples, I can open and edit a file, and pass properties to hide OpenOffice using “com.sun.star.beans.PropertyValue” but not work.

Here my code

  Try
   
    Dim objServiceManager As OLEObject
    Dim objCoreReflection As OLEObject
    Dim objDesktop As OLEObject
    Dim objDocument As OLEObject
    Dim objText As OLEObject
    Dim Replace As OLeObject
    Dim Aargs() As Variant
    Dim FileP as OLEObject
    
 
    objServiceManager = New OLEObject("com.sun.star.ServiceManager")
    'Create the CoreReflection service that is later used to create structs
    objCoreReflection = objServiceManager.createInstance("com.sun.star.reflection.CoreReflection")
    
    'Create the Desktop
    objDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop")

'------------------------------------------------------
  'Problem, this part not WORK!!! 
    FileP=objServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
    FileP.Name="Hidden"
    FileP.Value=True
 '-----------------------------------------------------   
    
    Aargs.Append(FileP)
   
    objDocument= objDesktop.loadComponentFromURL(FileName.URLPath, "_blank", 0, Aargs)
    
      Catch E as OLEException
    MsgBox "open office error"
  End

Any idea?

Nicola I have tested your program and it works. But you have to make sure you have the LibreOffice Document before you run the program… The error might just be because it can not find the document… Anyway I have attached an example that works for me…

Before you run this test. Make sure you have created a LibreOffice Document and saved it at: C:\test1.odt With Password: secret

The code consist of one PushButton and one Method

PushButton1.Action

  Try
    
    Dim objServiceManager As OLEObject
    Dim objCoreReflection As OLEObject
    Dim objDesktop As OLEObject
    Dim objDocument As OLEObject
    Dim objText As OLEObject
    Dim Replace As OLeObject
    Dim Aargs() As Variant
    Dim FileP as OLEObject
        
    objServiceManager = New OLEObject("com.sun.star.ServiceManager")
    'Create the CoreReflection service that is later used to create structs
    objCoreReflection = objServiceManager.createInstance("com.sun.star.reflection.CoreReflection")
    
    'Create the Desktop
    objDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop")
    
    Aargs.Append(MakePropertyValue("ReadOnly", True))
    Aargs.Append(MakePropertyValue("Password", "secret"))
    Aargs.Append(MakePropertyValue("Hidden", False))
    
    // Make sure you have created a libreoffice document in C: 
    // and saved it as "test1.odt" with Password: secret
    // before you run this program
    
    objDocument= objDesktop.loadComponentFromURL("file:///c:/test1.odt", "_blank", 0, Aargs)

   objServiceManager = nil
    
  Catch E as OLEException
    MsgBox "open office error"
  End

One Method:
Function MakePropertyValue(cName As String, uValue As Variant) AS OleObject

  Dim oPropertyValue As OleObject
  Dim oSM As OLEObject
  
  oSM = New OLEObject("com.sun.star.ServiceManager")
  oPropertyValue = oSM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
  oPropertyValue.Name = cName
  oPropertyValue.Value = uValue
 
  oSm = nil

 Return oPropertyValue

More examples you can find on Programming OpenOffice.org with Visual Basic

Thanks for the answer John,
But the program works in half, the parameter with the password works, but others do not, file is not opened for read only, and if set Hidden to true, nothing changes.

Yes you are right… I only noticed the “Save” Icon was faded out. Should have modified the document, then I would have realized it…

I have tried with different versions On windows XP and Windows 7:
OpenOffice Version 3.0 (have even tried to use “Name=OpenFlags, Value=H” which are deprecated in newer versions)
LibreOffice 3.3
LibreOffice 4.1

All the same problem… Since it accept the Password, I presume the arguments is working, but Boolean has to be entered different, or it is a bug in Xojo OleObject. I guess we have to search for some more information about this.

Link to PropertyValue

Yes, I tried to set the Hidden parameter to true, but when I read the parameter value is False.
There seems to be a problem with the Boolean values.

Created a Feedback case: 37706

You will find the solution here https://forum.xojo.com/43165-example-how-to-open-libreoffice-document-as-readonly-with-use-o/0