[Libreoffice-bugs] [Bug 131564] Cannot set cell number format to percentage + 1 decimal from VBA macro (locale-dependent)

bugzilla-daemon at bugs.documentfoundation.org bugzilla-daemon at bugs.documentfoundation.org
Sun Jun 28 14:15:57 UTC 2020


https://bugs.documentfoundation.org/show_bug.cgi?id=131564

--- Comment #4 from Andreas Heinisch <andreas.heinisch at yahoo.de> ---
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

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice-bugs/attachments/20200628/b675da8a/attachment.htm>


More information about the Libreoffice-bugs mailing list