Getting integer value from spreadsheet as Variable

3 replies [Last post]
iFunction
Offline
Last seen: 5 days 19 hours ago
Title: ★★★
Joined: 10 May 2016
Posts: 23
Hi there,

I am trying to get an integer value from Cell(4, 14) this is currently 422 on my spreadsheet, I can get it out as a text, but if I format it on the sheet to a number, all I can get out of this cell is 0. Here is the code I am using, the first one is for text with that cell formatted to text, the second one is for (What I was hoping would be) an Integer:


Dim j As String

oSheet = ThisComponent.CurrentSelection.Spreadsheet

j = oSheet.getCellByPosition(4, 14).Text
msgbox j
p. 

Here the answer I get is 422

Dim j As Integer

oSheet = ThisComponent.CurrentSelection.Spreadsheet

j = oSheet.getCellByPosition(4, 14).Value
msgbox j
p. 

Here the same Cell with the same value (but now formatted to number) give 0.

How do you solve this? 
iFunction
Offline
Last seen: 5 days 19 hours ago
Title: ★★★
Joined: 10 May 2016
Posts: 23
And how do you do a code
And how do you do a code block in this forum, I can’t get that to work either
Zizi64
Offline
Last seen: 4 hours 39 min ago
Title: ★★★★★
Joined: 30 Sep 2010
Posts: 384
The value of a cell (when the
When the content of the cell is a String (Text), the value of the cell equals zero. You can ecamine the type of the cell content by some API functions:

Dim oDoc As Object
Dim oSheet As Object
Dim oCell As Object

oDoc = ThisComponent
oSheet = oDoc.getcurrentcontroller.activesheet
oCell = oSheet.getCellByPosition(4,14)

Select Case oCell.Type
Case com.sun.star.table.CellContentType.EMPTY
   MsgBox "Content: Empty"
Case com.sun.star.table.CellContentType.VALUE
   MsgBox "Content: Value"
Case com.sun.star.table.CellContentType.TEXT
   MsgBox "Content: Text"
Case com.sun.star.table.CellContentType.FORMULA
   MsgBox "Content: Formula"
End Select

Tibor Kovács Budapest, Hungary LO4.4.7, and LO5.1.1 Portable version; AOO4.1.2 on Win7×64Prof_SP1
iFunction
Offline
Last seen: 5 days 19 hours ago
Title: ★★★
Joined: 10 May 2016
Posts: 23
Thank you, this is incredibly
Thank you, this is incredibly useful!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.