Bonsoir François
Sub TestQueryKey
Dim oDoc As Object
Dim oSheet As Object
Dim oCell As Object
Dim oFormats As Object
Dim oFormat As Object
Dim sFormat As String
Dim NumFormat As Long
Dim oFrenchLocale As New com.sun.star.lang.Locale
With oFrenchLocale
.Country = "FR"
.Language = "fr"
End With
oDoc = ThisComponent
oFormats = oDoc.getNumberFormats()
oSheet = oDoc.getSheets().getByIndex ( 0 ) 'Feuille1
oCell = oSheet.getCellByPosition ( 1, 5 ) 'B6
oCell.setFormula ( "=TODAY()" )
sFormat = "DD/MM/YYYY"
'sFormat = "NNN J MMMM AAAA"
'queryKey( aFormat as string, nLocale as struct, bScan as boolean
) AS long
NumFormat = oFormats().queryKey( sFormat, oFrenchLocale, TRUE)
Pourquoi affectes-tu un format anglais, avec une locale french ?
Si je comprends bien queryKey renvoie -1 si le format n'existe pas ?
Ce que j'avais vu dans le livre de Bernard et Laurent.
Mais ce que je ne comprends pas c'est pourquoi après avoir
demandé les formats par _queryKeys_, j'obtiens un -1 sur un format
pourtant bien existant
A moins que la méthode queryKey ne manipule pas la même source de
données que queryKeys . Ce qui explique pourquoi tu ajoutes le format
ci-après.
???
'sFormat = "NNN J MMMM AAAA"
sFormat = "JJ MM AAAA"
'sFormat = "JJ MMM AAAA"
If NumFormat = -1 Then
'addNew ( aFormat as string, nLocale as struct ) AS long
NumFormat = oFormats().addNew ( sFormat, oFrenchLocale )
End If
oFormat = oFormats.getByKey(NumFormat)
xray oFormat
'le format de la cellule est mise à jour
oCell.NumberFormat = NumFormat
MsgBox oCell.NumberFormat & Chr(10) & oFormat.Type & Chr(10) &
oFormat.FormatString
End Sub