Bug 88949

Summary: Sort is failing in macro
Product: LibreOffice Reporter: Oliver King-Smith <oliverks1>
Component: BASICAssignee: LeMoyne Castle <lemoyne.castle>
Status: RESOLVED NOTABUG    
Severity: major CC: ilmari.lauhakangas, oliverks1
Priority: medium    
Version: 3.5.0 release   
Hardware: x86-64 (AMD64)   
OS: All   
Whiteboard:
Crash report or crash signature: Regression By:
Attachments: Example of sort macro failure

Description Oliver King-Smith 2015-01-30 15:20:37 UTC
Created attachment 112961 [details]
Example of sort macro failure

I have uploaded an example spreadsheet of the problem.

To see he bug, go to the sheet2 and run the Macro sort_data in Standard->Module1 of the spreadsheet.

Here are the partial results of the sorting

20	100mV	1596940	1601740	1595830
20	100mV	10121.9	10373.5	10585.2
22	100mV	1552090	1557190	1551480
				
				
				
22	100mV	9358	9568.9	9751
				
24.2	100mV	1511870	1517010	1511770
				
24.2	100mV	8704.12	8887.51	9046.9
				
26.62	100mV	1475550	1480690	1475820
				
26.62	100mV	8141.18	8300.78	8441.84
				
29.282	100mV	1427120	1431990	1427520


It is leaving black spaces.

If you run the sort from the menu option it runs fine.  Once the menu command has been run, the macro starts working. as expected.

Oliver
Comment 1 Buovjaga 2015-01-31 13:40:11 UTC
The spreadsheet you attached already has the blank spaces.
If I sort using Data - Sort and then insert a blank row, the macro leaves the blank row in place.

Same result with 3.5.0.

Did you verify that your macro is correct by asking on http://ask.libreoffice.org/ ?

Set to NEEDINFO.
Change back to UNCONFIRMED after you have provided the information.

Win 7 Pro 64-bit, LibO Version: 4.4.0.3
Build ID: de093506bcdc5fafd9023ee680b8c60e3e0645d7

Ubuntu 14.10 64-bit
LibreOffice 3.5.0rc3 
Build ID: 7e68ba2-a744ebf-1f241b7-c506db1-7d53735
Comment 2 LeMoyne Castle 2015-02-03 02:42:08 UTC
Problem is a bug in the BASIC.  getCellRangeByPosition call has the argument order swapped so that the sorted area is very wide and a few rows long instead of covering the desired range = used area of the sheet. 

Proper order: getCellRangeByPosition(Left, Top, Right, Bottom)

line 38> range = sheet.getCellRangeByPosition( 
cursor.getRangeAddress().StartRow,cursor.getRangeAddress().StartColumn, 
cursor.getRangeAddress().EndRow, cursor.getRangeAddress().EndColumn)
needs the row and column args swapped to be in the proper order.

Reference -- https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Cell_and_Cell_Range_Access 

Sort appears to work using either getCellRangeByName and getCellRangeByPosition to get the range, and it naturally displaces all the blank rows (from menu Data->Sort or in macro sub sort_data). I believe that the blank lines were there before the sort as a result of the sheet construction.  The range transposition simply left most of the sheet untouched.