You've already forked lazarus-ccr
fpspreadsheet: Read and write xlsx files with formulas containing internal references to a range of cells within the same sheet (e.g., 'SUM(Sheet2!A1:B5)' ).
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6403 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1689,6 +1689,12 @@ begin
|
|||||||
if sheet = nil then
|
if sheet = nil then
|
||||||
sheet := FWorksheet.Workbook.AddWorksheet(sheetName, true);
|
sheet := FWorksheet.Workbook.AddWorksheet(sheetName, true);
|
||||||
Result := TsCellExprNode.Create(self, sheet, CurrentToken, true)
|
Result := TsCellExprNode.Create(self, sheet, CurrentToken, true)
|
||||||
|
end else
|
||||||
|
if TokenType = ttCellRange then begin
|
||||||
|
sheet := FWorksheet.WorkBook.GetWorksheetByName(sheetName);
|
||||||
|
if sheet = nil then
|
||||||
|
sheet := FWorksheet.Workbook.AddWorksheet(sheetName, true);
|
||||||
|
Result := TsCellRangeExprNode.Create(self, sheet, CurrentToken);
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else if (TokenType = ttCellRange) then
|
else if (TokenType = ttCellRange) then
|
||||||
|
@ -852,6 +852,9 @@ type
|
|||||||
function GetNumberFormat(AIndex: Integer): TsNumFormatParams;
|
function GetNumberFormat(AIndex: Integer): TsNumFormatParams;
|
||||||
function GetNumberFormatCount: Integer;
|
function GetNumberFormatCount: Integer;
|
||||||
|
|
||||||
|
{ Calculation }
|
||||||
|
procedure CalcFormulas;
|
||||||
|
|
||||||
{ Clipboard }
|
{ Clipboard }
|
||||||
procedure CopyToClipboardStream(AStream: TStream; AFormat: TsSpreadsheetFormat;
|
procedure CopyToClipboardStream(AStream: TStream; AFormat: TsSpreadsheetFormat;
|
||||||
AParams: TsStreamParams = []);
|
AParams: TsStreamParams = []);
|
||||||
@ -1354,10 +1357,15 @@ end;
|
|||||||
"not calculated" they are calculated and then tagged as "calculated".
|
"not calculated" they are calculated and then tagged as "calculated".
|
||||||
This results in an iterative calculation procedure. In the end, all cells
|
This results in an iterative calculation procedure. In the end, all cells
|
||||||
are calculated.
|
are calculated.
|
||||||
|
|
||||||
|
NOTE: IF THE WORKSHEET CONTAINS CELLS WHICH LINK TO OTHER WORKSHEETS THEN
|
||||||
|
THIS CALCULATION MAY NOT BE CORRECT. USE THE SAME METHOD OF THE WORKBOOK
|
||||||
|
INSTEAD !!!
|
||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsWorksheet.CalcFormulas;
|
procedure TsWorksheet.CalcFormulas;
|
||||||
var
|
var
|
||||||
cell: PCell;
|
cell: PCell;
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
if (boIgnoreFormulas in Workbook.Options) then
|
if (boIgnoreFormulas in Workbook.Options) then
|
||||||
exit;
|
exit;
|
||||||
@ -9657,6 +9665,51 @@ begin
|
|||||||
Result := FNumFormatList.Count;
|
Result := FNumFormatList.Count;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
Calculates all formulas of the workbook.
|
||||||
|
|
||||||
|
Since formulas may reference not-yet-calculated cells, this occurs in
|
||||||
|
two steps:
|
||||||
|
1. All formula cells are marked as "not calculated".
|
||||||
|
2. Cells are calculated. If referenced cells are found as being
|
||||||
|
"not calculated" they are calculated and then tagged as "calculated".
|
||||||
|
This results in an iterative calculation procedure. In the end, all cells
|
||||||
|
are calculated.
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
|
procedure TsWorkbook.CalcFormulas;
|
||||||
|
var
|
||||||
|
cell: PCell;
|
||||||
|
p: Pointer;
|
||||||
|
sheet: TsWorksheet;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
if (boIgnoreFormulas in Options) then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
// prevent infinite loop due to triggering of formula calculation whenever
|
||||||
|
// a cell changes during execution of CalcFormulas.
|
||||||
|
inc(FCalculationLock);
|
||||||
|
try
|
||||||
|
// Step 1 - mark all formula cells as "not calculated"
|
||||||
|
for p in FWorksheets do begin
|
||||||
|
sheet := TsWorksheet(p);
|
||||||
|
for cell in sheet.Cells do
|
||||||
|
if HasFormula(cell) then
|
||||||
|
sheet.SetCalcState(cell, csNotCalculated);
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Step 2 - calculate cells. If a not-yet-calculated cell is found it is
|
||||||
|
for p in FWorksheets do begin
|
||||||
|
sheet := TsWorksheet(p);
|
||||||
|
for cell in TsWorksheet(sheet).Cells do
|
||||||
|
if HasFormula(cell) and (cell^.ContentType <> cctError) then
|
||||||
|
sheet.CalcFormula(cell);
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
dec(FCalculationLock);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Writes the selected cells to a stream for usage in the clipboard.
|
Writes the selected cells to a stream for usage in the clipboard.
|
||||||
Transfer to the clipboard has do be done by the calling routine since
|
Transfer to the clipboard has do be done by the calling routine since
|
||||||
|
Reference in New Issue
Block a user