Page 1 of 1

AsVariant returns 1 if cell is clear

Posted: Fri Oct 24, 2014 12:52 pm
by zvasku
Hello,

I have problem with AsVariant. If cell is clear, funtion returns value "1". I think the problem is in GetAsVariant:

function TXLSWorksheet.GetAsVariant(ACol, ARow: integer): Variant;
var
Cell: TXLSCellItem;
begin
if FCells.FindCell(ACol,ARow,Cell) then begin
case FCells.CellType(@Cell) of
xctNone,
xctBlank: Result := 0;
// xctCurrency,
xctFloat: Result := FCells.GetFloat(@Cell);
xctString: Result := FCells.GetString(@Cell);
xctBoolean: Result := FCells.GetBoolean(@Cell);
xctError: Result := Xc12CellErrorNames[FCells.GetError(@Cell)];
xctFloatFormula: Result := FCells.GetFormulaValFloat(@Cell);
xctStringFormula: Result := FCells.GetFormulaValString(@Cell);
xctBooleanFormula: Result := FCells.GetFormulaValBoolean(@Cell);
xctErrorFormula: Result := Xc12CellErrorNames[FCells.GetFormulaValError(@Cell)];
end;
end
else
Result := varNull; <------------------------------- Here must be Null, not varNull which is varType and integer consts
end;

Thanks
Zdenek

Re: AsVariant returns 1 if cell is clear

Posted: Wed Oct 29, 2014 6:54 am
by larsa
Hello

In the latest update AsVariant returns zero If there is an unknown variant type.

Re: AsVariant returns 1 if cell is clear

Posted: Wed Oct 29, 2014 4:58 pm
by zvasku
I think it should return Null as this is a purpose of Variant type.

Z

Re: AsVariant returns 1 if cell is clear

Posted: Fri Oct 31, 2014 8:25 am
by larsa
Hello

No, excel returns zero on empty cells and this is also how other functions work (AsInteger, AsFloat).

Re: AsVariant returns 1 if cell is clear

Posted: Fri Oct 31, 2014 12:48 pm
by zvasku
Ok.

How can I find that htere is nothing in cell?

Now I'm using

if not FindCell() then result:=Null

but I also need test for Blank Cell. How can I test if cell is blank?

Thanks
Zdenek

Re: AsVariant returns 1 if cell is clear

Posted: Fri Oct 31, 2014 1:04 pm
by larsa
Hello

You can use CellType. Example:

Code: Select all

  case XLS.Sheets[0].CellType[2,2] of
    xctNone          : ;     //* No cell.
    xctBlank         : ;     //* Blank cell.
    xctBoolean       : ;     //* Boolean cell.
    xctError         : ;     //* Cell with an error value.
    xctString        : ;     //* String cell.
    xctFloat         : ;     //* Floating point cell.
    xctFloatFormula  : ;     //* Formula cell where the result of the formula is a numeric value.
    xctStringFormula : ;     //* Formula cell where the result of the formula is a string value.
    xctBooleanFormula: ;     //* Formula cell where the result of the formula is a boolean value.
    xctErrorFormula  : ;      //* Formula cell where the result of the formula is an error value.
  end;

Re: AsVariant returns 1 if cell is clear

Posted: Fri Oct 31, 2014 4:13 pm
by zvasku
That is what I'm looking for.

Thanks
Zdenek