user3457016
user3457016

Reputation: 113

Automating LibreOffice Calc from outside via COM

I tried accessing a Sheet in an ODS doc. Everything works fine - I can access Named ranges and so on - but if I try to access a simple cell via its Row/Col indices I get an error...

Code is Lotus Notes basic (because of the Variants...)

Dim rowFieldNameIndex As Integer
Dim rowStartMergeIndex As Long
Dim I As Integer  
Dim oCell As Variant    ' Cell object.
Dim oSheet As Variant
Dim FieldName As String

    rowFieldNameIndex = Val( GetOODocProperty (pOOObj, "FieldNameRow"))
    rowStartMergeIndex = Val( GetOODocProperty (pOOObj, "MergeStartRow"))
    '--> both working

    If Not pOOobj Is Nothing Then
        Set oSheet = pOOobj.Sheets(0)

        MsgBox pOOobj.Sheets.Count           'works
        MsgBox oSheet.CellsEnumeration.Count
        'getCellByPosition(col,row)
        Set oCell = oSheet.getCellByPosition(1, 1)  'ERROR?!?!?  getCellByPosition is no tan Instance Member??? so how can I access a Cell

        OCell.String = "Test"
    End If  

Public Function GetOODocProperty (pOODoc As Variant, ByVal strVarName) As String
    Dim userProps As Variant

    On Error Resume Next
    'get UserDefined Properties
    Set userProps = pOODoc.DocumentProperties.getUserDefinedProperties()

    'Try to Remove; on Error Property doesen't exists yet
    If userProps.getPropertySetInfo().hasPropertyByName(strVarName) = True Then
           'http://api.openoffice.org/docs/common/ref/com/sun/star/beans/XPropertySet.html
         GetOODocProperty = userProps.getPropertyValue(strVarName)
    Else
        GetOODocProperty = ""
    End If
End function

Upvotes: 1

Views: 422

Answers (1)

user3457016
user3457016

Reputation: 113

the problem was:

pOOBJ.Sheets(0) does not return a sheet Object in COM!!!!

this will work:

pOOObj.GetSheets().getbyIndex(0)

Upvotes: 1

Related Questions