Bug 131564 - Cannot set cell number format to percentage + 1 decimal from VBA macro (locale-dependent)
Summary: Cannot set cell number format to percentage + 1 decimal from VBA macro (local...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-VBA
  Show dependency treegraph
 
Reported: 2020-03-25 11:56 UTC by NISZ LibreOffice Team
Modified: 2022-06-29 03:38 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:
Regression By:


Attachments
Example file from Excel (14.47 KB, application/vnd.ms-excel.sheet.macroEnabled.12)
2020-03-25 11:56 UTC, NISZ LibreOffice Team
Details
Screenshot of the original document side by side in Excel and Calc after running the macro (91.26 KB, image/png)
2020-03-25 11:56 UTC, NISZ LibreOffice Team
Details
Screenshot of the original document side by side in Excel and Calc after running the macro in Calc with en-US locale (78.19 KB, image/png)
2020-03-25 11:57 UTC, NISZ LibreOffice Team
Details

Note You need to log in before you can comment on or make changes to this bug.
Description NISZ LibreOffice Team 2020-03-25 11:56:25 UTC
Created attachment 158977 [details]
Example file from Excel

Attached file contains a simple macro to set cell number format to percentage with 1 decimal place.
This call does not work in Calc with hu-HU locale, but works with en-US locale.

Columns("B").NumberFormat = "0.0%"

Steps to reproduce:
1.	Open attached xlsm file
2.	Run the macro in Excel and Calc

Actual results:
Values in column B: 1 and 12,5 become in Excel 100,0% and 1250,0% and 10.0% and 125.0% in Calc

However this works correctly with en-US locale since the decimal separator is dot there, but comma in hu-HU.

Expected results:
Macro works regardless of locale.

LibreOffice details:
Version: 7.0.0.0.alpha0+ (x64)
Build ID: bc898e2c2784e36ad4d4cdf6d962e39069d2c82d
CPU threads: 4; OS: Windows 6.3 Build 9600; UI render: Skia/Raster; VCL: win; 
Locale: hu-HU (hu_HU); UI-Language: en-US
Calc: CL
Comment 1 NISZ LibreOffice Team 2020-03-25 11:56:48 UTC
Created attachment 158978 [details]
Screenshot of the original document side by side in Excel and Calc after running the macro
Comment 2 NISZ LibreOffice Team 2020-03-25 11:57:02 UTC
Created attachment 158979 [details]
Screenshot of the original document side by side in Excel and Calc after running the macro in Calc with en-US locale
Comment 3 Andreas Heinisch 2020-03-28 16:31:42 UTC
Confirmed with:

Version: 6.3.3.2 (x64)
Build-ID: a64200df03143b798afd1ec74a12ab50359878ed
CPU-Threads: 6; BS: Windows 10.0; UI-Render: GL; VCL: win; 
Gebietsschema: de-DE (de_DE); UI-Sprache: de-DE
Calc: CL
Comment 4 Andreas Heinisch 2020-06-28 14:15:57 UTC
There exists a workaround, if you set the locale. However, it is still an inconvenience.

Function cellRange_SetNumberFormat( strSourceRange As String, strNumberFormat As String ) As Long
REM Sets the Number Format of the specified CellRange to <strNumberFormat>.
REM <strNumberFormat> : The desired Number Format specification string (e.g. "0.00").
REM NB. The given Format will be added to the NumberFormats, if it doesn't exist already.
    Dim aLocale As New com.sun.star.lang.Locale
    Dim oNumberFormats As Object    : oNumberFormats = ThisComponent.getNumberFormats()
    Dim oSheet As Object    : oSheet = ThisComponent.CurrentController.ActiveSheet
    Dim oRange As Object    : oRange = oSheet.getCellRangebyName( strSourceRange )
    Dim lFormatKey  As Long : lFormatKey = oNumberFormats.queryKey( strNumberFormat, aLocale, FALSE )
    If lFormatKey = -1 Then   lFormatKey = oNumberFormats.addNew( strNumberFormat, aLocale )
    oRange.NumberFormat = lFormatKey
    cellRange_SetNumberFormat = lFormatKey
End Function

Sub Main
    cellRange_SetNumberFormat("B1:B2", "0.0%")
End Sub
Comment 5 QA Administrators 2022-06-29 03:38:42 UTC
Dear NISZ LibreOffice Team,

To make sure we're focusing on the bugs that affect our users today, LibreOffice QA is asking bug reporters and confirmers to retest open, confirmed bugs which have not been touched for over a year.

There have been thousands of bug fixes and commits since anyone checked on this bug report. During that time, it's possible that the bug has been fixed, or the details of the problem have changed. We'd really appreciate your help in getting confirmation that the bug is still present.

If you have time, please do the following:

Test to see if the bug is still present with the latest version of LibreOffice from https://www.libreoffice.org/download/

If the bug is present, please leave a comment that includes the information from Help - About LibreOffice.
 
If the bug is NOT present, please set the bug's Status field to RESOLVED-WORKSFORME and leave a comment that includes the information from Help - About LibreOffice.

Please DO NOT

Update the version field
Reply via email (please reply directly on the bug tracker)
Set the bug's Status field to RESOLVED - FIXED (this status has a particular meaning that is not 
appropriate in this case)


If you want to do more to help you can test to see if your issue is a REGRESSION. To do so:
1. Download and install oldest version of LibreOffice (usually 3.3 unless your bug pertains to a feature added after 3.3) from https://downloadarchive.documentfoundation.org/libreoffice/old/

2. Test your bug
3. Leave a comment with your results.
4a. If the bug was present with 3.3 - set version to 'inherited from OOo';
4b. If the bug was not present in 3.3 - add 'regression' to keyword


Feel free to come ask questions or to say hello in our QA chat: https://web.libera.chat/?settings=#libreoffice-qa

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

Warm Regards,
QA Team

MassPing-UntouchedBug