AsVariant returns 1 if cell is clear

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
zvasku
Posts: 14
Joined: Wed Aug 01, 2012 2:22 pm

AsVariant returns 1 if cell is clear

Post 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
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: AsVariant returns 1 if cell is clear

Post by larsa »

Hello

In the latest update AsVariant returns zero If there is an unknown variant type.
Lars Arvidsson, Axolot Data
zvasku
Posts: 14
Joined: Wed Aug 01, 2012 2:22 pm

Re: AsVariant returns 1 if cell is clear

Post by zvasku »

I think it should return Null as this is a purpose of Variant type.

Z
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: AsVariant returns 1 if cell is clear

Post by larsa »

Hello

No, excel returns zero on empty cells and this is also how other functions work (AsInteger, AsFloat).
Lars Arvidsson, Axolot Data
zvasku
Posts: 14
Joined: Wed Aug 01, 2012 2:22 pm

Re: AsVariant returns 1 if cell is clear

Post 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
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: AsVariant returns 1 if cell is clear

Post 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;
Lars Arvidsson, Axolot Data
zvasku
Posts: 14
Joined: Wed Aug 01, 2012 2:22 pm

Re: AsVariant returns 1 if cell is clear

Post by zvasku »

That is what I'm looking for.

Thanks
Zdenek
Post Reply