| Summary: | Sorting, oCellRange.Sort(oSortDesc()), 3 columns by column#2 but column#3 sorted | ||
|---|---|---|---|
| Product: | LibreOffice | Reporter: | Nick <NALong007> |
| Component: | BASIC | Assignee: | Not Assigned <libreoffice-bugs> |
| Status: | RESOLVED WORKSFORME | ||
| Severity: | normal | CC: | andreas.heinisch, buzea.bogdan, rafael.palma.lima |
| Priority: | medium | ||
| Version: | 7.3.2.2 release | ||
| Hardware: | All | ||
| OS: | Windows (All) | ||
| Whiteboard: | |||
| Crash report or crash signature: | Regression By: | ||
| Attachments: | Test file and macros as requested | ||
|
Description
Nick
2022-09-16 20:42:49 UTC
Can you share a sample file with the data you used for testing as well as with your implementation of the macro? Created attachment 182832 [details]
Test file and macros as requested
I made an error in my original report. Sorting B in A, B, & C works but sorting E in D, E & F does not work. F is sorted.
Hope this helps.
At first, I could reproduce the issue in which columns C, D, and E did not work in sorting the columns. When I changed the oSortFields(0).Field = 4 to oSortFields(0).Field = 1 for test 2 it seems to work to show the sorted column 2. Version: 7.4.2.3 (x64) / LibreOffice Community Build ID: 382eef1f22670f7f4118c8c2dd222ec7ad009daf CPU threads: 8; OS: Windows 10.0 Build 22000; UI render: Skia/Raster; VCL: win Locale: en-US (en_US); UI: en-US Calc: threaded Thanks for your input. You confirmed the bug I was reporting The macro Test1 sorts colmuns A, B & C by index 1 (column B) correctly. The macro Test2 is supposed to sort columns D, E & F by index 4 (column E) but it does not. Columns D, E & F are equal to columns A, B & C. So the question is "Why does sorting by index 1 for A, B and C work but sorting by index 4 for D, E & F which should produce the same result but it does not?" The Field of the oSortFields variable is not counted from the beginning of a sheet, but counted relatively from the selected range. So, if you want to sort the data contained in column E, you don't have to specify the Field parameter from the beginning of the sheet, but from the beginning of the range: REM Range from D to F sText2 = "$D$1:$F$5" oCellRange = oSheet.getCellRangeByName(sText2) REM Sort by Column E descending (D has index 0, E has index 1, and F has index 2) oSortFields(0).Field = 1 oSortFields(0).SortAscending = TRUE oSortFields(0).FieldType = com.sun.star.util.SortFieldType.NUMERIC Imho, this needs some clarification in the documentation. Many thanks!!! In more than my humble opinion, the documentations NEEDS to be changed to show the index is from the the specified range. As far as I know, any other index is specified from the sheet. Note that Tammy found the same problem I did by using the sheet index. Again, thank you. I updated the description in https://wiki.documentfoundation.org/Macros/Calc/ba023 SUPER! Thanks. |