[Solved] Get cell data type via macro?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Archdeacon
Posts: 3
Joined: Tue Mar 20, 2012 5:30 am

[Solved] Get cell data type via macro?

Post by Archdeacon »

I am new to Open Office (but do know VB however) so please forgive a dumb question! How do I determine the data type of a cell (VALUE,FORMULA,STRING) when iterating through a loop in a macro. I need to insert FORMULA only when the data is type Value.
Last edited by Hagar Delest on Tue Mar 20, 2012 9:01 am, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 3.1 on Windows 7
FJCC
Moderator
Posts: 9653
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Get cell data type via macro?

Post by FJCC »

Here is an example:

Code: Select all

oSheet = ThisComponent.Sheets.getByName("Sheet1")
oCell = oSheet.getCellrangeByName("B1")
if oCell.Type = com.sun.star.table.CellContentType.VALUE Then
	Print "Yes"
End if
The possible values of CellContentType are here: http://www.openoffice.org/api/docs/comm ... tType.html
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Archdeacon
Posts: 3
Joined: Tue Mar 20, 2012 5:30 am

Re: Get cell data type via macro?

Post by Archdeacon »

Many thanks indeed for yor prompt reply!
OpenOffice 3.1 on Windows 7
User avatar
karolus
Volunteer
Posts: 1252
Joined: Sat Jul 02, 2011 9:47 am

Re: [Solved] Get cell data type via macro?

Post by karolus »

Hallo
Another example:

Code: Select all

...
oSheet = ThisComponent.Sheets.getByName("Sheet1")
oRange = oSheet.getCellrangeByName("B1:F100")
ValueCells =    oRange.querycontentcells(1).createEnumeration
        do while ValueCells.hasmoreElements()
            cell = ValueCells.nextElement
            cell.Formula = "bla"
        loop
...
Karo
Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
Post Reply