FlexCelGrid data extraction

Hello I am manually inserting a lot of data from a database into a FlexCelGrid through code, for example...


My question is... how can I do the reverse and copy the contents of my FlexCelGrid ?
or how can I sum a column in a grid using delphi code?

I have not exported the grid to excel, so I cannot use the FlexCelImport and I don't wish to export the results and have my users run excel to do the calculation and then re import back to my app.

I can use a string grid for this but this creates double the processing to produce the string grid and then display the results in the FlexCelGrid, I would much rather load all the data once then manipulate  (sum a column) to get a result.

Please help 


FlexCel grid doesn't hold any data on its own, it is a visual component. Data is always stored in the FlexCelImport component that is attached to the FlexCelGrid. (so it isn't stored twice).

If you look at the code for FlexCelGrid.SetCell, it just sets the data in the backing FlexCelImport:

procedure TFlexCelGrid.SetCell(const aRow, aCol: integer; const Text: UTF16String);
  if not Assigned(FFlexCelImport) or not FFlexCelImport.IsLoaded then exit;
  if (Length(Text)>0) and (Text[1] = '=') then
      FFlexCelImport.AssignCellFormulaX(aRow, aCol, Text, null);
      //    nothing, is not a valid formula.
  FFlexCelImport.SetCellString(aRow, aCol, Text);

  //InvalidateRow(aRow) doesnt work if the grid is scrolled horizontally... on D5 at least;

So, in order to get the values of the FlexCelGrid, you can just call Cell[row, col] in the attached FlexCelImport. 
You can also set the cells directly in the FlexCelImport component, and those changes will be shown in the FlexCelGrid. FlexCelImport doesn't use Excel at all, and there is not need to export the grid to Excel to use it. The grid is the one using FlexCelImport, not the other way around.


ok thanks for explaining that.

Another question the data stored in the cell is a TXLsCellValue.

How do I convert this to a 'real float'  or even to a 'string'  to process,  so I can sum my columns?

please help again

Thank you

TXlsCellValue has a field "value" that has a variant with the value of the cell. If the cell has a float (or something that can be converted to a float), then this code:

    val: TXlsCellValue;
    v: extended;
  v := val.Value;

will do.

Thanks again, I now remember seeing the ' .value' option before.

Best Regards