Bug 161069 - The script for adding a drop-down list to cells does not work correctly
Summary: The script for adding a drop-down list to cells does not work correctly
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.6.4.1 release
Hardware: All Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-14 10:54 UTC by Sirius34
Modified: 2024-05-14 12:20 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
test_add_list.xlsm Normal file, before script execute. (19.92 KB, application/vnd.ms-excel.sheet.macroenabled.12)
2024-05-14 10:56 UTC, Sirius34
Details
test_add_list_with_err.xlsm, file after script execute, contain errors (10.73 KB, application/vnd.ms-excel.sheet.macroenabled.12)
2024-05-14 10:57 UTC, Sirius34
Details
scr_err_list.jpg. Screenshot for demonstration the error after script execute. (13.92 KB, image/jpeg)
2024-05-14 10:59 UTC, Sirius34
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sirius34 2024-05-14 10:54:43 UTC
Description:
The file "test_add_list.xlsm" has a script for the Workbook_Open event, which, when opening the file, re-binds the drop-down list to the column cells (through data validation).
The lists are linked with the usual VBA code.
The problem is that, for reasons I don't understand, this script works correctly in Excel, and in Calc it works without errors, but the necessary directory is not linked. (screenshot)
There are no problems when opening in Calc a file with an already linked list.
If I save a file in which the script worked incorrectly, and then try to open it again, as in Excel and Calc, the file opens with errors, and the Workbook_open script does not work completely.

If I understood correctly, then the whole difficulty is that Calc addresses other sheets in a different way.

in Excel = guides!$A$3:$A$9
in Calc = $guides.$A$3:$A$9

Steps to Reproduce:
1. Open a file containing the workbook_open script that adds lists to cells.
2. Allow macros to be executed.
3. We get an incorrect result.

Actual Results:
We get an incorrect result (on screenshot).

Expected Results:
The lists must be added correctly in accordance with the VBA code.


Reproducible: Always


User Profile Reset: No

Additional Info:
The presence of this problem has been tested on LibreOffice version 7.6.4.1, on Windows 10/11 and Linux Mint 21.3 operating systems.
Resetting the user profile settings was not applied.
Comment 1 Sirius34 2024-05-14 10:56:16 UTC
Created attachment 194109 [details]
test_add_list.xlsm
Normal file, before script execute.
Comment 2 Sirius34 2024-05-14 10:57:30 UTC
Created attachment 194110 [details]
test_add_list_with_err.xlsm, file after script execute, contain errors
Comment 3 Sirius34 2024-05-14 10:59:18 UTC
Created attachment 194111 [details]
scr_err_list.jpg. Screenshot for demonstration the error after script execute.
Comment 4 Mike Kaganski 2024-05-14 11:25:52 UTC
Repro using Version: 24.2.3.2 (X86_64) / LibreOffice Community
Build ID: 433d9c2ded56988e8a90e6b2e771ee4e6a5ab2ba
CPU threads: 24; OS: Windows 10.0 Build 22631; UI render: default; VCL: win
Locale: en-GB (ru_RU); UI: en-GB
Calc: CL threaded

Changing the Workbook_Open macro to use "=guides.$A$3:$A$9" instead of "=guides!$A$3:$A$9", and executing it manually, fixes the Validity drop-down to list items from 2019 to 2025.

To require Calc syntax in VBA-specific calls is a bug, it must take Excel-specific syntax, and convert internally.

The code pointer is ScVbaValidation::Add [1], which eventually calls XSheetCondition::setFormula1 / setFormula2 UNO API, which indeed takes Calc-standard syntax. The strings must be converted prior to passing there (see e.g. ScVbaRange::setFormulaValue [2], which is used in ScVbaRange::setFormula / setFormulaR1C1 / setFormulaLocal).

[1] https://opengrok.libreoffice.org/xref/core/sc/source/ui/vba/vbavalidation.cxx?r=b3a90323#233
[2] https://opengrok.libreoffice.org/xref/core/sc/source/ui/vba/vbarange.cxx?r=0cd07e1f#1677