Hallo und guten Morgen,
ich habe ein Problem beim Umwandeln des lokalen NumberFormats in das StandardFormat einer Calc-Zelle. Die Umwandlung läuft in Basic zur Laufzeit.
Die Konstanten sind hier in der API beschrieben.
UNO Konstanten
Das eigentliche Problem betrifft das Format CURRENCY. Als Short definiert mit dem Wert = 8.
Zur Klarstellung:
Zunächst wird der durch das Makro Wert in die Zelle geschrieben:
Sub setCellStandardFormat(oCell As Object , Constant As Long )
Dim nKey As Long
Dim oDoc As Object
oDoc = thisComponent
Select Case Constant
Case _NUMBER
nKey = oDoc.NumberFormats.getStandardFormat( _
_NUMBER, _
oDoc.CharLocale)
Case _CURRENCY
nKey = oDoc.NumberFormats.getStandardFormat( _
_CURRENCY, _
oDoc.CharLocale)
Case _DATE
nKey = oDoc.NumberFormats.getStandardFormat( _
_DATE, _
oDoc.CharLocale)
Case _TIME
nKey = oDoc.NumberFormats.getStandardFormat( _
_TIME, _
oDoc.CharLocale)
Case _DATETIME
nKey = oDoc.NumberFormats.getStandardFormat( _
_DATETIME, _
oDoc.CharLocale)
Case _PERCENT
nKey = oDoc.NumberFormats.getStandardFormat( _
_PERCENT, _
oDoc.CharLocale)
Case _SCIENTIFIC
nKey = oDoc.NumberFormats.getStandardFormat( _
_SCIENTIFIC, _
oDoc.CharLocale)
Case _FRACTION
nKey = oDoc.NumberFormats.getStandardFormat( _
_FRACTION, _
oDoc.CharLocale)
Case _LOGICAL
nKey = oDoc.NumberFormats.getStandardFormat( _
_LOGICAL, _
oDoc.CharLocale)
Case _TEXT
nKey = oDoc.NumberFormats.getStandardFormat( _
_TEXT, _
oDoc.CharLocale)
End Select
oCell.NumberFormat = nKey
End Sub
Als Ergebnis erhält die Zelle den Index des lokalen Formats (z.B. de_DE). Die Sub erwartet die Zelle und eine Konstante. In diesem konkreten Fall die 8 für CURRENCY. Der lokale Wert (Index: 10115) wird in die Zelle geschrieben und Calc zeigt die Zelle korrekt an.
Das Problem beginnt bei dem umgekehrten Weg. Ich lese die Zelle aus, und der lokale Index soll nun wieder den Standard Index liefern:
Sub getStandardFormatType (oCell As object) As Long
Dim oDoc As Object
Dim oFormats As Object
Dim oFormat As Object
Dim nKey As Long
oDoc = ThisComponent
nKey = oCell.NumberFormat
oFormats = oDoc.NumberFormats
oFormat = oFormats.getByKey(nKey)
getStandardFormatType = oFormat.Type
End Sub
Die Sub liefert nun den Wert 9, der Überhaupt nicht definiert ist. Hat dazu jemand eine Erklärung oder Lösung?