Bug with SetCellFromString?

Hello,


I declare
XLSNeighbors      : TExcelFile;
str : string;
If I write then a str it normally goes ok.
XLSNeighbors.SetCellFromString(Row,Col,str);

If I write a str='58e' then automatically the Excel-cell
looks like this: 
5,80E+01

How can this be avoided?

Sincerely

Peter

Hi,

SetCellFromString tries to convert a string to whatever datatype it might be. As you can imagine, there is some guessing going on, and the solution might not be unique. In some cases, more than a solution is possible, and SetCellFromtring has to guess which is the one you want. Is the string '4/3' a fraction, or maybe march 4, or april 3? Or is 1.2 a number or feb 2 with german dates?

For this reason, you should use SetCellFromString only when you already have strings and you want to enter them. But it is not 100% reliable, and it is not possible to do it 100% reliable.

In your case, the string "58e" is interpreted as a number with an exponent, which it could be. StrToFloat('58e') will return the number 5.08e+01 after all. 

If you want to enter the string 58e, then the best is to use:
XLSNeighbors.SetCellValue(Row, Col, '58e');

To enter the number 58e, you would use:
XLSNeighbors.SetCellValue(Row, Col, 58e1);

Whenever possible, just enter the direct datatypes (doubles, strings, dates) into the cell. If you can't, you'll have to use SetCellFromString, but sadly this is not exact science. There are cases where you will get a bad guess.

Hi,


Thank you very much. This did the job!

Sincerely
Peter