(Peter, please test these, but my primary question is directed at the dev mailing list.....)

Tested on 3.3.0 en-US using the 64-bit Linux version on Fedora 15.

I use the following macro to find an existing number format, and I create it if it does not exist. The problem is that oDoc.getNumberFormats().queryKey(sFormat, aLocale, True) fails to find user created numeric formats, it only returns a value for for formats strings contained in the document.

Function FindCreateNumberFormatStyle (sFormat As String, Optional doc, Optional locale)
  Dim oDoc As Object
  Dim aLocale As New com.sun.star.lang.Locale
  Dim oFormats As Object
  Dim formatNum As Integer
  oDoc = IIf(IsMissing(doc), ThisComponent, doc)
  oFormats = oDoc.getNumberFormats()
  If ( Not IsMissing(locale)) Then
    aLocale = locale
  End If
  formatNum = oFormats.queryKey (sFormat, aLocale, True)
  MsgBox "Current Format number for " & sFormat & " is " & formatNum
  'If the number format does not exist then add it
  If (formatNum = -1) Then
    formatNum = oFormats.addNew(sFormat, aLocale)
    If (formatNum = -1) Then formatNum = 0
    MsgBox "New Format number for " & sFormat & " is " & formatNum
  End If
  FindCreateNumberFormatStyle = formatNum
End Function

So, here is my test macro. The first time, the macro runs fine. The second time, the macro fails.

Sub TestFormat
  Dim dummy1$
  Dim i As Integer
  Dim n As Long
  Dim formats()
formats() = Array("0", "#,##0", "$#,##0.--;[RED]-$#,##0.--", "##0,0#\h", "##0,0#\°C", "#0,0#\W\h", "##0,0#\k\W\h")
  For i = LBound(formats()) To UBound(formats())
    n = FindCreateNumberFormatStyle (formats(i))
  Next
End Sub

For certain the macro adds the formats that it fails to find. This macro lists all the formats in the document.

Sub ListFormatsInCurrentDocument()
  Dim oDoc           ' Document created to hold the format strings.
  Dim oFormats       ' Formats in the current document.
  Dim oFormat        ' Current format object.
  Dim oData          ' Keys queried from the formats.
  Dim i%             ' General index variable.
  Dim sFormat$       ' Current format string.
  Dim sPrevFormat$   ' Previous format string.
  Dim aLocale as new com.sun.star.lang.Locale

  oFormats = ThisComponent.getNumberFormats()

  ' Create an output document.
oDoc = StarDesktop.loadComponentFromURL( "private:factory/swriter", "_blank", 0, Array() ) oData = oFormats.queryKeys(com.sun.star.util.NumberFormat.ALL, aLocale, False)
  For i = LBound(oData) To UBound(oData)
    oFormat=oFormats.getbykey(oData(i))
    sFormat=oFormat.FormatString
    If sFormat<>sPrevFormat Then
      sPrevFormat=sFormat
      oDoc.getText().insertString(oDoc.getText().End, _
CStr(oData(i)) & CHR$(9) & sFormat & CHR$(10), False)
    End If
  Next
End Sub


Certainly I can first use the quick check and if that fails, then troll the entire list before creating a format, but that just feels silly. Off hand, I do believe that this macro used to work as expected.

--
-----------------------------------------------------------------
To unsubscribe send email to dev-unsubscr...@api.openoffice.org
For additional commands send email to sy...@api.openoffice.org
with Subject: help

Reply via email to