Here is my code:
I want the last cell to be result of a divison of cell x by cell y using holdcol1 and holdcol2
After the excel sheet is opened, if some changes the value in cell x or cell y, the value in cell z will change.
procedure TMain.DoExport;
var col, row, i, holdcol1, holdcol2 : Integer;
begin
XLS.BeginUpdate;
for row := 1 to 3 do
begin
col := 0;
XLS.Sheets[0].AsFloat[col, row] := Row * 100; // cell x
holdCol1 := col;
inc(col);
XLS.Sheets[0].AsString[col, row] := 'Hello';
inc(col);
XLS.Sheets[0].AsString[col, row] := 'World';
inc(col);
XLS.Sheets[0].AsFloat[col, row] := 25; // cell y
holdcol2 := col;
inc(Col);
// now I want to divide cell x by cell y - HOW DO I DO IT?
//XLS.Sheets[0].AsFormula[col, row] := ? // cell z
end;
XLS.EndUpdate;
end;
Thanks in advance
AsFormula?
Re: AsFormula?
This partially works:
XLS.Sheets[0].AsFormula[col, row] := FloatToStr(XLS.Sheets[0].AsFloat[holdcol1, row] /
XLS.Sheets[0].AsFloat[holdcol2, row]);
But cell z does not change with a change in cell x or cell y when the spread sheet is opened.
TIA
XLS.Sheets[0].AsFormula[col, row] := FloatToStr(XLS.Sheets[0].AsFloat[holdcol1, row] /
XLS.Sheets[0].AsFloat[holdcol2, row]);
But cell z does not change with a change in cell x or cell y when the spread sheet is opened.
TIA
Re: AsFormula?
finally got it
colrow1 := ColRowToRefStr(holdcol1, row, false, false);
colrow2 := ColRowToRefStr(holdcol2, row, false, false);
ref := colrow1 + '/' + colrow2;
XLS.Sheets[0].AsFormula[col, row] := ref;
colrow1 := ColRowToRefStr(holdcol1, row, false, false);
colrow2 := ColRowToRefStr(holdcol2, row, false, false);
ref := colrow1 + '/' + colrow2;
XLS.Sheets[0].AsFormula[col, row] := ref;