https://bugs.freedesktop.org/show_bug.cgi?id=74807

          Priority: medium
            Bug ID: 74807
          Assignee: [email protected]
           Summary: RTL: 'getCells' method of the XSheetCellRanges
                    interfaces produces unexpected behavior (often empty
                    or partial container contents returned)
          Severity: normal
    Classification: Unclassified
                OS: Windows (All)
          Reporter: [email protected]
          Hardware: Other
        Whiteboard: BSA PossibleRegression
            Status: UNCONFIRMED
           Version: 4.2.0.4 release
         Component: Spreadsheet
           Product: LibreOffice

Problem description: Previously, one could iterate through all of the single
cells in a SheetCellRanges object by using the getCells() method and then
creating an enumeration with createEnumeration(). This is particularly useful
when using something like "queryContentCells" on a SheetCellRange to find cells
filled with some content, or perhaps using the com.sun.star.util.XSearchable
inteface and a SearchDescriptor to find cells matching some criteria, and then
iterate through each cell.

A workaround is instead to access each contained SheetCellRange within the
SheetCellRanges (using getByIndex), and then iterate through each cell of each
contained SheetCellRange (using getCellByPosition).

Steps to reproduce:
- Fill a com.sun.star.sheet.SheetCellRanges object with some cell ranges
(manually or with some search function like queryContentCells or findAll)
- call the getCells method (oSheetCellRanges.getCells()) and inspect the
returned container

Routines to reproduce the problem:

Sub GetCellsBugExample()

    Dim oCalcDoc as Object
    Dim oSheet as Object
    Dim oSheetCellRanges as Object

    ' Create a spreadsheet document
    oCalcDoc = StarDesktop.loadComponentFromURL( "private:factory/scalc",
"_default", 0, array() )

    ' Generate some searchable data
    oSheet = oCalcDoc.Sheets(0)
    oSheet.getCellRangeByName("C10").setString("Something")
    oSheet.getCellRangeByName("C1:E2").setDataArray( Array( Array("A","B","C"),
Array("X","Y","Something") ) )
    oSheet.getCellRangeByName("A1:A4").setDataArray( Array( Array("Hello"),
Array("World"), Array("How are"), Array("You?") ) )

    REM USING queryContentCells
        oSheetCellRanges = oSheet.queryContentCells(
com.sun.star.sheet.CellFlags.STRING )
        ' Select the cells in the document
        oCalcDoc.CurrentController.select( oSheetCellRanges )
        ' Test the SheetCellRanges object
        TestSheetCellRanges( oSheetCellRanges )
        oSheetCellRanges = Nothing

    REM USING Search Descriptor
    Dim oSearch as Object
        oSearch = oSheet.createSearchDescriptor()
        With oSearch
            .SearchRegularExpression = FALSE
            .searchString = "Something"
            .SearchType = 1
            .SearchBackwards = FALSE
            .SearchWords = TRUE
            .SearchCaseSensitive = TRUE
        End With
        oSheetCellRanges = oSheet.FindAll( oSearch )
        ' Select the cells in the document
        oCalcDoc.CurrentController.select( oSheetCellRanges )
        ' Test the SheetCellRanges object
        TestSheetCellRanges( oSheetCellRanges )
        oSheetCellRanges = Nothing

    REM Manually using createInstance
    Dim oRangeAddress as New com.sun.star.table.CellRangeAddress
        oSheetCellRanges =
oCalcDoc.createInstance("com.sun.star.sheet.SheetCellRanges")
        With oRangeAddress
            .Sheet = 0
            .StartColumn = 0
            .StartRow = 0
            .EndColumn = 0
            .EndRow = 3
        End With
        oSheetCellRanges.addRangeAddress( oRangeAddress, FALSE )
        With oRangeAddress
            .Sheet = 0
            .StartColumn = 4
            .StartRow = 0
            .EndColumn = 4
            .EndRow = 0
        End With
        oSheetCellRanges.addRangeAddress( oRangeAddress, FALSE )
        ' Select the cells in the document
        oCalcDoc.CurrentController.select( oSheetCellRanges )
        ' Test the SheetCellRanges object
        TestSheetCellRanges( oSheetCellRanges )
        oSheetCellRanges = Nothing

    ' Close the spreadsheet
    oCalcDoc.close(TRUE)
End Sub

Sub TestSheetCellRanges( ByRef oSheetCellRanges as Object )
    On Error GoTo ErrorHandler

    Dim oRange as Object
    Dim oCells as Object

    Dim eCells as Object
    Dim oCell as Object
    Dim lRange as Long
    Dim lCol as Long
    Dim lRow as Long
    Dim lColMax as Long
    Dim lRowMax as Long

    Dim sMsg as String
    sMsg = ""

    ' Make sure the object supports the SheetCellRanges Service
    If NOT
oSheetCellRanges.supportsService("com.sun.star.sheet.SheetCellRanges") Then
        Exit Sub
    End If
    ' Make sure the object exporst the XSheetCellRanges Interfaces
    If NOT
hasUnoInterfaces(oSheetCellRanges,"com.sun.star.sheet.XSheetCellRanges") Then
        Exit Sub
    End If

    ' Check to see if the SheetCellRanges is empty
    sMsg = sMsg & Chr(10) & "oSheetCellRanges.getCount() = " &
oSheetCellRanges.getCount()
    ' Double check by printing out it's Absolute Name
    sMsg = sMsg & Chr(10) & "oSheetCellRanges.AbsoluteName = " &
oSheetCellRanges.AbsoluteName

    ' Call the "getCells" method to fetch what should be a container of all of
the cells in the SheetCellRanges
    oCells = oSheetCellRanges.getCells()

    ' Check to see if the cells container is emtpy
    If oCells.hasElements() Then
        sMsg = sMsg & Chr(10) & "oCells.hasElements() = TRUE"
        ' Enumerate the cells and print each cell name
        eCells = oCells.createEnumeration()
        While eCells.hasMoreElements()
            oCell = eCells.nextElement()
            sMsg = sMsg & Chr(10) & oCell.AbsoluteName & " - " &
oCell.getString()
        Wend
    Else
        sMsg = sMsg & Chr(10) & "oCells.hasElements() = FALSE"
        ' Iterate through each contained range
        For lRange = 0 To (oSheetCellRanges.getCount() - 1)
            oRange = oSheetCellRanges.getByIndex(lRange)
            lColMax = oRange.RangeAddress.EndColumn -
oRange.RangeAddress.StartColumn
            lRowMax = oRange.RangeAddress.EndRow - oRange.RangeAddress.StartRow
            ' iterate through each column
            For lCol = 0 To lColMax
                ' iterate through each row
                For lRow = 0 To lRowMax
                    oCell = oRange.getCellByPosition(lCol,lRow)
                    sMsg = sMsg & Chr(10) & oCell.AbsoluteName & " - " &
oCell.getString()
                Next lRow
            Next lCol
        Next lRange
    End If

    MsgBox sMsg

    Exit Sub
    ErrorHandler:
        MsgBox "Error " & err & ": " & error$ + chr(13) + "In line : " + Erl +
chr(13) + Now
End Sub


Current behavior:
The returned container from getCells() is either empty or contains only some of
the cells within the SheetCellRanges

Expected behavior:
The returned container from getCells() should return every
com.sun.star.sheet.SheetCell object that is contained by the
com.sun.star.sheet.SheetCellRanges object.
Operating System: Windows 7
Version: 4.2.0.4 release
Last worked in: 4.1.4.2 release

-- 
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
Libreoffice-bugs mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/libreoffice-bugs

Reply via email to