Read the type of a cell, from a spreadsheet

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Albireo
Posts: 1756
Joined: 16 Oct 2013, 13:53

Read the type of a cell, from a spreadsheet

24 Jun 2016, 06:12

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?
User avatar
lifeweaver
Posts: 144
Joined: 10 May 2014, 05:57
Location: OH
Contact:

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

24 Jun 2016, 08:10

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.
Albireo
Posts: 1756
Joined: 16 Oct 2013, 13:53

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

25 Jun 2016, 04:10

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
just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

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

25 Jun 2016, 04:22

Code: Select all

GetCellTypeAsString(oCell) {
   Static CellTypes := {0: "Empty", 1: "Value", 2: "Text", 3: "Formula"}
   Return (CellType := CellTypes[oCell.getType()]) ? CellType : "Unknown"
}
*not tested*
Albireo
Posts: 1756
Joined: 16 Oct 2013, 13:53

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

25 Jun 2016, 16:41

Thanks!
How to use the function?
just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

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

26 Jun 2016, 04:53

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)
;)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mebelantikjaya, NinjoOnline and 285 guests