AsFormula?

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
Mojoala
Posts: 19
Joined: Wed Feb 29, 2012 5:54 pm

AsFormula?

Post by Mojoala »

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
Mojoala
Posts: 19
Joined: Wed Feb 29, 2012 5:54 pm

Re: AsFormula?

Post by Mojoala »

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
Mojoala
Posts: 19
Joined: Wed Feb 29, 2012 5:54 pm

Re: AsFormula?

Post by Mojoala »

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;

:lol:
Post Reply