Issue 54374 - NumberFormat not properly preserved on a save
Summary: NumberFormat not properly preserved on a save
Status: CONFIRMED
Alias: None
Product: General
Classification: Code
Component: code (show other issues)
Version: OOo 2.0.3
Hardware: All All
: P3 Trivial with 2 votes (vote)
Target Milestone: AOO Later
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-08 19:47 UTC by andrew
Modified: 2017-05-20 11:31 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description andrew 2005-09-08 19:47:38 UTC
I created a numeric property 

0 (###) ### ## ##

I saved the document, loaded the document, and then the numeric property is
shown as:

#" ("###") "###" "##" "#0


This is true in both 1.1.4 and 1.95.126. Next, I inspected the numeric format
and noticed that the number of leading zeros is set to 1. From my perspective,
this makes the two different numeric formats identical. The problem is that the
number is NOT properly displayed when the document is reloaded.

To test this, 
1. Create a Write document with a text table. 
2. Add the text 123456789 into a cell.
3. Select the text 123456789.
4. Run the following macro:

Sub SetFormat
  Dim i%
  Dim oSels, oSel
  oSels = ThisComponent.getCurrentController().getSelection()
  For i = 0 To oSels.getCount()-1
    oSel = oSels.getByIndex(i)
    If NOT IsEmpty(oSel.Cell) Then 
      oSel.Cell.NumberFormat = FindCreateNumberFormatStyle("0 (###) ### ## ##")
      Print "Set to " & oSel.Cell.NumberFormat
    End if
  Next
End Sub

'******************************************************************
'Author: Andrew Pitonyak
'email:   andrew@pitonyak.org
Function FindCreateNumberFormatStyle (_
  sFormat As String, Optional doc, Optional locale)
  Dim oDocument As Object
  Dim aLocale as new com.sun.star.lang.Locale
  Dim oFormats As Object
  Dim formatNum As Integer
  oDocument = IIf(IsMissing(doc), ThisComponent, doc)
  oFormats = oDocument.getNumberFormats()
  'If you choose to query on types, you need to use the type
  'com.sun.star.util.NumberFormat.DATE
  'I could set the locale from values stored at
  'http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt
  'http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html
  'I use a NULL locale and let it use what ever it likes.
  'First, see if the number format exists
  If ( Not IsMissing(locale)) Then
    aLocale = locale
  End If
  formatNum = oFormats.queryKey (sFormat, aLocale, TRUE)
  MsgBox "Current Format number 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 is " & formatNum
  End If
  FindCreateNumberFormatStyle = formatNum
End Function 

Now, inspect the number format that was created. You can use the following macro
if you desire: Be certain to place the cursor outside of the table before
running this macro.

Sub enumFormats()
  'Author : Laurent Godard
  'e-mail : listes.godard@laposte.net
  'Modified : Andrew Pitonyak
  Dim vText
  Dim vFormats, vFormat
  Dim vTextCursor, vViewCursor
  Dim iMax As Integer, i As Integer
  Dim s$
  Dim PrevChaine$, Chaine$
  Dim aLocale as new com.sun.star.lang.Locale
 
  vFormats = ThisComponent.getNumberFormats()
  'RunSimpleObjectBrowser(vFormats)
  vText = ThisComponent.Text
  vViewCursor = ThisComponent.CurrentController.getViewCursor()
  vTextCursor = vText.createTextCursorByRange(vViewCursor.getStart())
  Dim v
  v = vFormats.queryKeys(com.sun.star.util.NumberFormat.ALL, aLocale, False)
  For i = LBound(v) To UBound(v)
    vFormat=vFormats.getbykey(v(i))
    chaine=VFormat.FormatString
    If Chaine<>Prevchaine Then
      PrevChaine=Chaine
      chaine=CStr(v(i)) & CHR$(9) & CHR$(9) & chaine & CHR$(10)
      vText.insertString(vTextCursor, Chaine, FALSE)
    End If
  Next
  MsgBox "Finished"
End Sub 

If you save the document, close the document, and open the document, the number
format will change (acceptable), but the displayed number will also change (not
acceptable).
Comment 1 Olaf Felka 2006-03-07 13:04:20 UTC
@ jsk: Please have a look.
Comment 2 joerg.skottke 2006-03-31 06:35:46 UTC
To NN. Maybe we should raise the prio because this is some sort of dataloss?
Comment 3 gercokees 2006-08-04 14:31:37 UTC
I have same sort of problem in Calc...
Do not no wheter to start a new issue or append additonal info here...
To reproduce:
In Calc, cell A1 enter: 1,111111
now goto: Format -> Styles and Formating and create a new style.
in tab: numbers enter the formatcode: 0,0##
aply the style to cell A1
Notice the format of cell A1

Close (save) and open the file.
Notice that the format of cell A1 has now changed...
Notice that the formatcode in your custum style has changed...

Changed version to 2.0.3

Gerco-Kees
<><
Comment 4 Marcus 2017-05-20 11:31:03 UTC
Reset assigne to the default "issues@openoffice.apache.org".