Calc BASIC: Check cell content type in DATE

 Sub CheckCellType
	Dim oDoc, oSheet, oCell	As Object		
	oDoc        = ThisComponent
	oSheet		= oDoc.Sheets.getByName("Sheet1")
	oCell		= oSheet.getCellByPosition(0,1)
	Select Case oCell.Type
		Case com.sun.star.table.CellContentType.EMPTY		'0
			Print "Cell type = " & oCell.Type & " / EMPTY"
		Case com.sun.star.table.CellContentType.VALUE		'1
			Print "Cell type = " & oCell.Type & " / VALUE"
		Case com.sun.star.table.CellContentType.TEXT		'2
			Print "Cell type = " & oCell.Type & " / TEXT"
		Case com.sun.star.table.CellContentType.FORMULA	'3
			Print "Cell type = " & oCell.Type & " / FORMULA"
	End Select
End Sub

Both examples, the result is the same, 1, VALUE. How could it be identified more in NUMBER or DATE ?

image description
image description

The cell content for a date is a number; how it is displayed is controlled by the formatting of the cell.

Hello,

i think you (also) have to check the Numberformat value.

oCell.NumberFormat

This table from the macro bible might be usefull

Hope that helps.


To show the community your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!


Have a nice day and let’s (continue to) “Be excellent to each other!”


Ask / Getting Started:

https://wiki.documentfoundation.org/Ask/Getting_Started

In addition to what @igorlius already posted:
See LibreOffice: com::sun::star::table Module Reference.
Unfortunately the term type is differently used (misused?) in different places. After all, the mandatory specifications of ODF for spreadsheets describe Time, Date, DateTime, Percantage (!!), Currency, Logical (Number), and even Complex Number (which is implemented technically as text in Calc) as subtypes of Number.

This doubtable approach is threadbarely implemented in Calc by automatisms during the process of recognition after entering data, setting a respective format. It causes misunderstandings and errors again and again, imo.

Concerning the case Complex Number there isn’t even a distinction by format. You may test any text only semantically for being acceptable as one.