2009/9/18 Darren Forster <[email protected]>:
> Is there anyway to convert the Cell.Formula value into a Cell.String value
> in OpenOffice Basic?  I've thought maybe Cell.Formula.String would work but
> it doesn't.

If you have Xray installed, you can see what options you have with an object.
Don't set variables directly if there are methods for it. In this case
there are methods like setBlahblahblah and getBlahblahblah(), so use
them.

To examine an object with Xray, try something like this:

Option Explicit
Sub Test
        Dim Sheet As Object, Cell As Object
        Sheet=ThisComponent.getSheets().getByName("Sheet1")
        Cell=Sheet.getCellByPosition(0,0)
        
        Xray Cell
End Sub

A dialogue opens and you can select what kind of information you want.
Select Methods and click the Sort A-Z button. Now look for stuff that
begins with get and set.

Well, that was not an answer to your question, but I'm not sure I understand it…

Let's say we have a cell and we want the formuia:

Option Explicit
Sub Test
        Dim Sheet As Object, Cell As Object
        Sheet=ThisComponent.getSheets().getByName("Sheet1")
        Cell=Sheet.getCellByPosition(0,0)
        
        Dim TheFormula As String
        TheFormula=Cell.getFormula()
End Sub

TheFormula now contains the cell formula of A1 which is a string.
Let's say that A1 contains "=B1+B2", and let's assume that B1=40 and
B2=50. Are you saying that you now would like Cell.String to be "90"
or perhaps "B1+B2"?

I did some experimenting, and if you want the same effect as Paste
Special → Text+Numbers, this should work:

Option Explicit

Sub Test
        Dim Sheet As Object, Cell As Object
        Sheet=ThisComponent.getSheets().getByName("Sheet1")
        Cell=Sheet.getCellByPosition(0,0)
        
        Cell.setFormula(Cell.getString())
End Sub

Or maybe this is more what you are looking for:

Sub Test
        Dim Sheet As Object, Cell As Object
        Sheet=ThisComponent.getSheets().getByName("Sheet1")
        Cell=Sheet.getCellByPosition(0,0)
        
        Cell.setString(Cell.getString())
End Sub


In the example above, A1 will now contain '90. The ' is not displayed,
but 90 will be aligned to the left.

Johnny Rosenberg


>
> Also the same for converting from Formula to Value it would be really handy
> if there was.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to