Bug 135242 - Calc: Macro - sorting is working just for first 3 criteria
Summary: Calc: Macro - sorting is working just for first 3 criteria
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
6.4.5.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro Sorting
  Show dependency treegraph
 
Reported: 2020-07-28 17:29 UTC by BogdanB
Modified: 2024-03-28 14:38 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
video showing the bug (2.66 MB, video/mp4)
2020-07-28 17:33 UTC, BogdanB
Details
the file with the problem described (21.00 KB, application/vnd.oasis.opendocument.spreadsheet)
2020-07-28 17:33 UTC, BogdanB
Details

Note You need to log in before you can comment on or make changes to this bug.
Description BogdanB 2020-07-28 17:29:58 UTC
Description:
The exemple file attached contains a macro that is executed when we press Ctrl+S (when we save the document).

When executed what should happend:
Sort by column 16		ASCENDING
Than by column 17		DESCENDING
Than by column 23		DESCENDING
Than by column 20		ASCENDING
Than by column 21		ASCENDING

What is happend:
Sort by column 16		ASCENDING
Than by column 17		DESCENDING
Than by column 23		DESCENDING

Last 2 options are ignored.


See the video, it's much easier to understand the bug.

Steps to Reproduce:
The exemple file attached contains a macro that is executed when we press Ctrl+S (when we save the document).

When executed what should happend:
Sort by column 16		ASCENDING
Than by column 17		DESCENDING
Than by column 23		DESCENDING
Than by column 20		ASCENDING
Than by column 21		ASCENDING

What is happend:
Sort by column 16		ASCENDING
Than by column 17		DESCENDING
Than by column 23		DESCENDING

Last 2 options are ignored.

Actual Results:
The last 2 sorting criteria are ignored.

Expected Results:
The last 2 sorting criteria are executed.


Reproducible: Always


User Profile Reset: Yes



Additional Info:
Version: 6.4.5.2
Build ID: a726b36747cf2001e06b58ad5db1aa3a9a1872d6
CPU threads: 4; OS: Linux 5.4; UI render: default; VCL: gtk3; 
Locale: ro-RO (ro_RO.UTF-8); UI-Language: en-US
Calc: threaded
Comment 1 BogdanB 2020-07-28 17:33:22 UTC
Created attachment 163706 [details]
video showing the bug
Comment 2 BogdanB 2020-07-28 17:33:46 UTC
Created attachment 163707 [details]
the file with the problem described
Comment 3 BogdanB 2020-07-28 17:34:32 UTC
Code in MACRO that is executed:

REM  *****  BASIC  *****

Sub Main

End Sub


sub Macro1
rem ----------------------------------------------------------------------
rem define variables
dim document  as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "DbName"
args1(0).Value = "bd"

dispatcher.executeDispatch(document, ".uno:SelectDB", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(17) as new com.sun.star.beans.PropertyValue
args2(0).Name = "ByRows"
args2(0).Value = true
args2(1).Name = "HasHeader"
args2(1).Value = true
args2(2).Name = "CaseSensitive"
args2(2).Value = false
args2(3).Name = "NaturalSort"
args2(3).Value = false
args2(4).Name = "IncludeAttribs"
args2(4).Value = true
args2(5).Name = "UserDefIndex"
args2(5).Value = 0

args2(6).Name = "Col1"
args2(6).Value = 16
args2(7).Name = "Ascending1"
args2(7).Value = true

args2(8).Name = "Col2"
args2(8).Value = 17
args2(9).Name = "Ascending2"
args2(9).Value = false

args2(10).Name = "Col3"
args2(10).Value = 23
args2(11).Name = "Ascending3"
args2(11).Value = false

args2(12).Name = "Col4"
args2(12).Value = 20
args2(13).Name = "Ascending4"
args2(13).Value = true

args2(14).Name = "Col5"
args2(14).Value = 21
args2(15).Name = "Ascending5"
args2(15).Value = true

args2(16).Name = "IncludeComments"
args2(16).Value = false
args2(17).Name = "IncludeImages"
args2(17).Value = true

dispatcher.executeDispatch(document, ".uno:DataSort", "", 0, args2())

end sub

Sub Macro2

End Sub
Comment 4 Mike Kaganski 2020-07-28 19:43:27 UTC
Confirming using Version: 7.1.0.0.alpha0+ (x64)
Build ID: b18c44e7e467ab872dc6283d558c57d91ead45cb
CPU threads: 12; OS: Windows 10.0 Build 18363; UI render: Skia/Raster; VCL: win
Locale: ru-RU (ru_RU); UI: en-US
Calc: CL.

Code pointer: ScCellShell::ExecuteDB (case SID_SORT) in sc/source/ui/view/cellsh2.cxx. The API case only considers three keys (aSortParam.maKeyState[0 to 2]).
Comment 5 BogdanB 2020-07-28 19:54:33 UTC
If I go to sort, I can use 5 criteria for sorting.
How can be MACRO forced to use 5 criteria like in manual sort?
Comment 6 Mike Kaganski 2020-07-28 19:57:03 UTC
See also SfxVoidItem DataSort SID_SORT in sc/sdi/scalc.sdi, where only 14 parameters are defined, with keys limited to Col1 - Col3.
Comment 7 BogdanB 2021-01-15 21:06:20 UTC
Tested also in
Version: 7.2.0.0.alpha0+
Build ID: 5adc93a9a9426ef79054751be2904896f787a8a2
CPU threads: 4; OS: Linux 5.8; UI render: default; VCL: gtk3
Locale: ro-RO (ro_RO.UTF-8); UI: en-US
Calc: threaded

Not working.
Comment 8 Andreas Heinisch 2021-02-13 09:57:34 UTC Comment hidden (obsolete)
Comment 9 Andreas Heinisch 2021-02-13 09:58:52 UTC
The fix of bug 105301 did not fix this bug. Previously, I had the wrong bug number.
Comment 10 Andreas Heinisch 2021-02-15 17:46:50 UTC
If you want to sort for more than 3 columns, you may use these approaches:
https://ask.libreoffice.org/en/question/111683/macro-sort-only-allows-3-criteria/ or https://ask.libreoffice.org/en/question/111683/macro-sort-only-allows-3-criteria/.

Is there a possibilty in SfxVoidItem DataSort SID_SORT in sc/sdi/scalc.sdi to change the api to a dynamic number of columns?
Comment 11 BogdanB 2024-03-28 14:38:20 UTC
Retested.
Also in
Version: 24.2.0.3 (X86_64) / LibreOffice Community
Build ID: da48488a73ddd66ea24cf16bbc4f7b9c08e9bea1
CPU threads: 4; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: ro-RO (ro_RO.UTF-8); UI: en-US
Calc: threaded