Page 1 of 1

Read the type of a cell, from a spreadsheet

Posted: 24 Jun 2016, 06:12
by Albireo
Hi!
My desire is to be able to read the type of content in a specific cell, in a spreadsheet.

This example below, is from "Andrew Pitonyak - Macros Explained" and written in Basic.

Code: Select all

Function GetCellType(oCell) As String
  Select Case oCell.getType() 
  Case com.sun.star.table.CellContentType.EMPTY
    GetCellType = "Empty"
  Case com.sun.star.table.CellContentType.VALUE
    GetCellType = "Value"
  Case com.sun.star.table.CellContentType.TEXT
    GetCellType = "Text"
  Case com.sun.star.table.CellContentType.FORMULA
    GetCellType = "Formula"
  Case Else
    GetCellType = "Unknown"
  End Select 
End Function
As I understand, nothing has happened with the desire of a "Case" function in AHK?
Is it possible to translate this, or something like that to AHK?

Re: Read the type of a cell, from a spreadsheet

Posted: 24 Jun 2016, 08:10
by lifeweaver
Hi Albireo,

You are correct nothing has happened with a 'Case', or 'Switch' statement.
You might consider using an Associative array, set the 'com.sun.star.table.CellContentType.EMPTY' as the key and the value as the string like 'Empty'.

So something like:

Code: Select all

Array := Object()
Array["com.sun.star.table.CellContentType.EMPTY"] := "Empty"
Array["com.sun.star.table.CellContentType.VALUE"] := "Value"
;......

; Then to use something like:
GetCellType := Array[oCell.getType()]
Or you could SubStr() the 'com.sun.star.table.CellContentType.EMPTY' and merely get the text after the last period I supose.

Re: Read the type of a cell, from a spreadsheet

Posted: 25 Jun 2016, 04:10
by Albireo
Thank you!
But the result was "" (Nothing)

If I only use the instruction oCell.getType()I got the following result .:
0 => Emty
1 => Value
2 => String
3 => Formula

Re: Read the type of a cell, from a spreadsheet

Posted: 25 Jun 2016, 04:22
by just me

Code: Select all

GetCellTypeAsString(oCell) {
   Static CellTypes := {0: "Empty", 1: "Value", 2: "Text", 3: "Formula"}
   Return (CellType := CellTypes[oCell.getType()]) ? CellType : "Unknown"
}
*not tested*

Re: Read the type of a cell, from a spreadsheet

Posted: 25 Jun 2016, 16:41
by Albireo
Thanks!
How to use the function?

Re: Read the type of a cell, from a spreadsheet

Posted: 26 Jun 2016, 04:53
by just me
Albireo wrote:If I only use the instruction oCell.getType()I got the following result .:
0 => Emty
1 => Value
2 => String
3 => Formula

Code: Select all

CellType := GetCellTypeAsString(oCell)
;)