Bug 150464 - calc macro using uno:numberformatvalue displays different formats in cell on different spreadsheets and computers for the same value
Summary: calc macro using uno:numberformatvalue displays different formats in cell on ...
Status: CLOSED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
7.3.5.2 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-18 01:02 UTC by Tom
Modified: 2022-08-18 08:41 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom 2022-08-18 01:02:48 UTC
Description:
The macro as follows
Sub srCellFormat(sSpread As String, sCellRange As String, iFormatType As Integer)
Dim oDocument  		As Object
Dim oDispatcher  		As Object
	srSetActiveSheet(sSpread)
	oDocument      		= ThisComponent.CurrentController.Frame
	oDispatcher     		= createUnoService("com.sun.star.frame.DispatchHelper")
Dim aArgs1(0)   		As New com.sun.star.beans.PropertyValue
	aArgs1(0).Name  	= "ToPoint"
	aArgs1(0).Value 	= sCellRange
	oDispatcher.executeDispatch(oDocument, ".uno:GoToCell", "", 0, aArgs1())
Dim aArgs2(0)       	As New com.sun.star.beans.PropertyValue
	aArgs2(0).Name  	= "NumberFormatValue"
	aArgs2(0).Value 	= iFormatType
	oDispatcher.executeDispatch(oDocument, ".uno:NumberFormatValue", "", 0, aArgs2())
End Sub

Before I upgraded to Linux Mint Mate 21 and LO 7.3.5.2 it was working correctly with a value of 155 to give a format in dollars to 6 decimal places. Now it requires 109 or 110 and it will work when it wants to or even give a format to 3 decimal places

Steps to Reproduce:
1. Run the included macro using the following
2. sSpread is the sheet name, sCellRange is for  example "A1" and iFormatType is value to give the required number format
3.

Actual Results:
Instead of giving the required format it does what it pleases

Expected Results:
The cell to be format to dollars with 6 decimal places


Reproducible: Always


User Profile Reset: Yes


OpenGL enabled: Yes

Additional Info:
Give a correctly formatted cell to give the spreadsheet a good structured appearance
Version: 7.3.5.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 4; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Ubuntu package version: 1:7.3.5-0ubuntu0.22.04.1
Calc: threaded
Comment 1 Mike Kaganski 2022-08-18 05:26:17 UTC
I don't think that format codes are hard-coded. They may change per version, locale, and per document IIUC. So relying on specific numeric values is a user error.

Here it is shown how to get a number format ID from NumberFormats for a specified format string:

https://ask.libreoffice.org/t/how-to-create-a-macro-to-insert-the-current-date-in-the-current-language/28707/7

Eike: should this be marked NOTABUG?
Comment 2 Eike Rathke 2022-08-18 08:41:02 UTC
Internal enumeration of user-defined number formats is almost arbitrary and only consistent within one session within one document, it merely depends on the order the formats were created when reading the document or the user added them. For Calc, the only fixed enumeration values are the pre-defined number formats of the default locale that was effective when the number formatter of a document was created, see https://opengrok.libreoffice.org/xref/core/include/svl/zforlist.hxx?r=fbe169fa#122

See also the UNO API reference
https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1i18n_1_1NumberFormatIndex.html
https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1i18n_1_1XNumberFormatCode.html

Using the dispatcher with NumberFormatValue instead relies on implementation details.