I am experimenting with opening calc documents, and I have run in to a strange problem. The code below is supposed to open a file in read only mode, but the file is opened always in read/write mode, and if the file is open in another frame or on another machine, the LoadComponent... returns an exception with an error message "com.sun.star.lang.IllegalArgumentException Message: URL seems to be an unsupported one.."
Code: Select all
Sub Test
Dim oDoc, oSheet, oCell As object
Dim fileName As String
Dim FileProp(0) As New com.sun.star.beans.PropertyValue
FileProp(0).Name = "ReadOnly"
FileProp(0).Value = "true" 'I have tried "True" as well as "1"
fileName = ConvertToURL("C:\Users\user\Documents\TEMP\Test.ods")
oDoc = StarDesktop.loadComponentFromURL(fileName, "_blank", 0, FileProp()) 'I have also tried "FileProp" without brackets
if NOT IsEmpty(oDoc) Then
oSheet = oDoc.Sheets.getByName("test")
oCell = oSheet.getCellByPosition(2,4)
msgBox oCell.String
else
msgbox "Could not open file"
end if
End Sub
I can always use XSimpleFileAccess to copy the file to temporary location and delete it after use, but that is not an elegant solution in my mind.