Bug 74807 - RTL: 'getCells' method of the XSheetCellRanges interfaces produces unexpected behavior (often empty or partial container contents returned)
Summary: RTL: 'getCells' method of the XSheetCellRanges interfaces produces unexpected...
Status: NEEDINFO
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Spreadsheet (show other bugs)
Version: 4.2.0.4 release
Hardware: Other Windows (All)
: medium major
Assignee: Not Assigned
QA Contact:
URL:
Whiteboard: BSA PossibleRegression
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-10 19:39 UTC by Devfra
Modified: 2015-01-10 18:06 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Devfra 2014-02-10 19:39:25 UTC
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
Comment 1 Joel Madero 2014-06-21 01:05:22 UTC
Please attach a document with the macro in it. Marking as NEEDINFO - once you do please mark as UNCONFIRMED.
Comment 2 QA Administrators 2015-01-10 18:06:26 UTC
Dear Bug Submitter,

This bug has been in NEEDINFO status with no change for at least 6 months. Please provide the requested information as soon as possible and mark the bug as UNCONFIRMED. Due to regular bug tracker maintenance, if the bug is still in NEEDINFO status with no change in 30 days the QA team will close the bug as INVALID due to lack of needed information.

For more information about our NEEDINFO policy please read the wiki located here: 
https://wiki.documentfoundation.org/QA/FDO/NEEDINFO

If you have already provided the requested information, please mark the bug as UNCONFIRMED so that the QA team knows that the bug is ready to be confirmed.


Thank you for helping us make LibreOffice even better for everyone!


Warm Regards,
QA Team

Message generated on: 10/01/2015


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.