setDataArray(Object[][]) strange behaviour for Strings containing only Integers

View: New views
4 Messages — Rating Filter:   Alert me  

setDataArray(Object[][]) strange behaviour for Strings containing only Integers

by Steffen Boersig :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I encountered a strange behaviour for setDataArray(Object[][]) while
inserting several types of data. It seems like Strings, that contain
numbers only are inserted with a leading  ' .
If i want to insert " "5" " , " '5 " will be inserted. If i just insert
"5", the number will be inserted correctly.
I wrote a litte testing snippet:

            XCellRange cellRange2 = sheet.getCellRangeByPosition(0, 0,
1, 1);
            XCellRangeData data2 = (XCellRangeData)
UnoRuntime.queryInterface(XCellRangeData.class, cellRange2);
            Object[][] val = new Object[2][2];
            val[0][0] = "5";
            val[0][1] = 5;
            val[1][0] = " 5";
            val[1][1] = "'5";
            data2.setDataArray(val);

val[0][0] will be inserted as " '5 ", where as it should be inserted
just as "5" in my opinion.
Same with val[1][0]. It's inserted as " '5".

 Is this a bug or is it working as inteded and it's just me not
understanding proper usage of this method?

Any information would be appreciated.

Specifications:

OOo 3.1.1(OOO310m19 Build9420), Java 1.5_017 and Windows XP.
I'm executing the code in OOoBean environment, but I think that
shouldn't matter.

Steffen Börsig

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...


Re: setDataArray(Object[][]) strange behaviour for Strings containing only Integers

by Niklas Nebel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10/22/09 12:57, Steffen Boersig wrote:
> val[0][0] will be inserted as " '5 ", where as it should be inserted
> just as "5" in my opinion.
> Same with val[1][0]. It's inserted as " '5".
>
> Is this a bug or is it working as inteded and it's just me not
> understanding proper usage of this method?

The string in the cell is "5" without the "'". The single quote is added
in the input line, and when editing, to allow editing of the string
instead of the number 5.

Niklas

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...


Re: setDataArray(Object[][]) strange behaviour for Strings containing only Integers

by Steffen Boersig :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


>
> The string in the cell is "5" without the "'". The single quote is
> added in the input line, and when editing, to allow editing of the
> string instead of the number 5.
>
> Niklas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@...
> For additional commands, e-mail: dev-help@...
>
Well,my problem is, that methods like String.equals() don't understand
that behaviour. Of course, in the GUI(at least while not looking at the
actual formula) it's shown correctly as a normal "5".
But if I'm calling cell.getFormula().equals("5") it's returning false.
Because actually in the formula there is a leading single quote.

Is XCell.getFormula() the wrong way to get a cells content/String? When
yes, which method should be used?
Is it possible to disable the leading single quote before inserting?


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...


Re: setDataArray(Object[][]) strange behaviour for Strings containing only Integers

by Niklas Nebel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10/22/09 14:52, Steffen Boersig wrote:
> Well,my problem is, that methods like String.equals() don't understand
> that behaviour. Of course, in the GUI(at least while not looking at the
> actual formula) it's shown correctly as a normal "5".
> But if I'm calling cell.getFormula().equals("5") it's returning false.
> Because actually in the formula there is a leading single quote.
>
> Is XCell.getFormula() the wrong way to get a cells content/String? When
> yes, which method should be used?
> Is it possible to disable the leading single quote before inserting?

Use getString from the com.sun.star.text.XTextRange interface (base of
XText). For getFormula/setFormula, "5" is a value cell.

Niklas

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...