[Solved] [Calc] Text to number

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
grahamn
Posts: 7
Joined: Sat Aug 16, 2014 4:15 am

[Solved] [Calc] Text to number

Post by grahamn »

I have the following code in a calc macro

Cell = Sheet.getCellByPosition(16,RowNo)
Cost = Cell.String
NewCost = Cost - 6
Cell = Sheet.getCellByPosition(16,RowNo)
Cell.String = NewCost

The result is a number expressed as a string, as expected, but I need a number to be able to carry out further calculations.
I have tried converting to a number using Cell.string = VAL(NewCost) and Cell.String = CSng(NewCost) but the result is still a string
Apparently I am doing something wrong but cannot find an answer after several searches.

Using Windows 10
Last edited by Hagar Delest on Thu Jun 11, 2020 8:27 am, edited 1 time in total.
Reason: tagged solved
OpenOffice 4.1.0 on windows 7
FJCC
Moderator
Posts: 9277
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: text to number

Post by FJCC »

If you want the cell value, use

Code: Select all

Cost = Cell.Value
Also, there is no needto do
Cell = Sheet.getCellByPosition(16,RowNo)
twice
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.
grahamn
Posts: 7
Joined: Sat Aug 16, 2014 4:15 am

Re: text to number

Post by grahamn »

Thanks FJCC
I'll keep this in mind for the future
OpenOffice 4.1.0 on windows 7
Post Reply