i |
[macro] Tester le contenu d'une cellule |
Sub LireCellBis
'=======variables========
dim v_2doc as object, v_2feuille as object, v_2cellTest as object
Dim v_2cellString as string, v_2valueT as variant, v_2cellType as variant
v_2doc=ThisComponent
v_2feuille=v_2doc.sheets.getbyname("Feuille1")
v_2cellTest=v_2feuille.getCellRangeByName("B2")
v_2valueT=v_2CellTest.Value
v_2cellType=v_2CellTest.Type 'pour voir
v_2cellString=v_2CellTest.String
'========================
Select Case v_2valueT
Case 1
msgbox "La cellule contient un nombre"
Case 2
msgbox "La cellule contient du texte"
Case 0
msgbox "La cellule contient l'expression : " +""""+v_2CellTest.string+""""
End Select
End Sub
PYS : Il est recommandé d'utiliser les constantes:
Par exemple :
select case oCell.Type
case com.sun.star.table.CellContentType.EMPTY
msgbox "cellule vide"
case com.sun.star.table.CellContentType.TEXT
msgbox "texte"
case com.sun.star.table.CellContentType.VALUE
msgbox "nombre"
case com.sun.star.table.CellContentType.FORMULA
msgbox "formule"
end select
select case oCell.Type
case com.sun.star.table.CellContentType.EMPTY
msgbox "cellule vide"
case com.sun.star.table.CellContentType.TEXT
msgbox "texte"
case com.sun.star.table.CellContentType.VALUE
msgbox "nombre"
case com.sun.star.table.CellContentType.FORMULA
msgbox "formule"
end select