lazarus-ccr/components/fpspreadsheet/examples/other/demo_recursive_calc.pas
wp_xxyyzz 5b946b751f fpspreadsheet: Add units (mm, cm, in, pts, lines/chars) for column width and row heights. Update all demos (some issues left).
NOTE: This revision breaks existing code if the worksheet's DefaultRowHeight/DefaultColWidth is changed - value must be in millimeters now. Methods for accessing individual row heiths and column widths are fine, but are marked as deprecated, they use the old units. Optionally a unit parameter can be specified.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4568 8e941d3f-bd1b-0410-a28a-d453659cc2b4
2016-03-18 19:50:40 +00:00

54 lines
1.5 KiB
ObjectPascal

{ This demo is a test for recursive calculation of cells. The cell formulas
are constructed such that the first cell depends on the second, and the second
cell depends on the third one. Only the third cell contains a number.
Therefore calculation has to be done recursively until the independent third
cell is found. }
program demo_recursive_calc;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
{$IFDEF UseCThreads}
cthreads,
{$ENDIF}
{$ENDIF}
Classes, Math,
fpstypes, fpspreadsheet, fpsfunc, xlsbiff8;
var
workbook: TsWorkbook;
worksheet: TsWorksheet;
const
OutputFile='test_recursive.xls';
begin
writeln('Starting program.');
workbook := TsWorkbook.Create;
try
workbook.Options := workbook.Options + [boCalcBeforeSaving];
worksheet := workbook.AddWorksheet('Calc_test');
worksheet.WriteColWidth(0, 20);
worksheet.WriteUTF8Text(0, 0, '=B2+1'); // A1
worksheet.WriteFormula(0, 1, 'B2+1'); // B1
worksheet.WriteUTF8Text(1, 0, '=B3+1'); // A2
worksheet.WriteFormula(1, 1, 'B3+1'); // B2
worksheet.WriteUTF8Text(2, 0, '(not dependent)'); // A3
worksheet.WriteNumber(2, 1, 1); // B3
workbook.WriteToFile(OutputFile, sfExcel8, true);
writeln('Finished.');
writeln;
writeln('Please open "'+OutputFile+'" in "fpsgrid".');
writeLn('It must show correct calculation results in cells B1 and B2.');
ReadLn;
finally
workbook.Free;
end;
end.