Recent

Author Topic: Function TsWorksheet.ReadNumericValue  (Read 2184 times)

Relativity

  • Full Member
  • ***
  • Posts: 103
Function TsWorksheet.ReadNumericValue
« on: February 28, 2018, 08:54:52 am »
What does the function TsWorksheet.ReadNumericValue do ?
What is the meaning of the returned Boolean value ?

I have to read Excel sheet cells and tell apart empty cells from cells containing zero: should I first read the cell content as a string, to check if it is empty ?

Thanks in advance.
"How'm I gonna get through?"
  -- Pet Shop Boys

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Function TsWorksheet.ReadNumericValue
« Reply #1 on: February 28, 2018, 09:15:56 am »
This is from the function comments (it should be in the chm file, too):
Quote
  Returns the numeric equivalent of the cell contents. This is the NumberValue
  of a number cell, the DateTimeValue of a date/time cell, the ordinal BoolValue
  of a boolean cell, or the string converted to a number of a string cell.
  All other cases return NaN.

  @param   ACell   Cell to be considered
  @param   AValue  (output) extracted numeric value
  @return  True if conversion to number is successful, otherwise false   

But I think this is overkill for you task. Just check the field NumberValue of the cell for zero:
Code: Pascal  [Select][+][-]
  1. function IsZero(ACell: PCell): Boolean;
  2. begin
  3.   Result := (ACell <> nil) and (ACell^.ContentType = cctNumber) and (ACell^.NumberValue = 0);
  4. end;

To get the cell at a given row/column call
Code: Pascal  [Select][+][-]
  1. var
  2.   cell: PCell;
  3. ...
  4.   cell := Worksheet.FindCell(ARow, ACol);

 

TinyPortal © 2005-2018