fpspreadsheet: Ignore the million of ods filler rows added by LibreOffice to Excel files - see memory overflow reported in http://forum.lazarus.freepascal.org/index.php/topic,34464.0.html)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5268 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2016-10-19 08:21:40 +00:00
parent f2907e713c
commit 45580a3c97
2 changed files with 21 additions and 10 deletions

View File

@ -3338,6 +3338,12 @@ var
s: String;
colsSpanned, rowsSpanned: Integer;
begin
// Workaround for Excel files converted to ods by Calc: These files are
// expanded to fill the entire max worksheet. They also have single empty
// cell in the outermost cells --> don't write anything here to prevent this.
if (ARow > FLimitations.MaxRowCount - 10) or (ACol > FLimitations.MaxColCount - 10) then
exit;
// select this cell value's type
paramValueType := GetAttrValue(ANode, 'office:value-type');
paramFormula := GetAttrValue(ANode, 'table:formula');
@ -3412,7 +3418,7 @@ end;
procedure TsSpreadOpenDocReader.ReadRowsAndCells(ATableNode: TDOMNode);
var
row: Integer;
rowNode, childnode: TDOMNode;
rNode, childnode: TDOMNode;
nodeName: String;
rowsRepeated: Integer;
colFmt: array of Integer;
@ -3478,7 +3484,8 @@ var
// If all cell styles in the row are the same then hasRowFormat is true
// and we can store the format of the first cell in the row record.
if GetRowFormat and hasRowFormat and
(col + colsRepeated >= LongInt(FLimitations.MaxColCount) - 10) then
(col + colsRepeated >= LongInt(FLimitations.MaxColCount) - 10) and
(row < FLimitations.MaxRowCount - 10) then
begin
lRow := FWorksheet.GetRow(row);
// Find first cell in row, all cells have the same format here.
@ -3523,7 +3530,7 @@ var
cellNode := cellNode.NextSibling;
end; //while Assigned(cellNode)
s := GetAttrValue(RowNode, 'table:number-rows-repeated');
s := GetAttrValue(ARowNode, 'table:number-rows-repeated');
if s = '' then
rowsRepeated := 1
else
@ -3580,10 +3587,10 @@ begin
isFirstRow := true;
PrintRowMode := false;
rownode := ATableNode.FirstChild;
while Assigned(rowNode) do
rnode := ATableNode.FirstChild;
while Assigned(rNode) do
begin
nodename := rowNode.NodeName;
nodename := rNode.NodeName;
// Repeated print rows
if nodeName = 'table:table-header-rows' then
@ -3591,7 +3598,7 @@ begin
PrintRowMode := true;
if FRepeatedRows.FirstIndex = Cardinal(UNASSIGNED_ROW_COL_INDEX) then
FRepeatedRows.FirstIndex := row;
childnode := rowNode.FirstChild;
childnode := rNode.FirstChild;
while Assigned(childnode) do
begin
nodename := childnode.NodeName;
@ -3606,9 +3613,9 @@ begin
else
// "normal" rows
if nodeName = 'table:table-row' then
ProcessRow(rowNode, true);
ProcessRow(rNode, true);
rowNode := rowNode.NextSibling;
rNode := rNode.NextSibling;
end;
// Construct column records with column format

View File

@ -4473,6 +4473,8 @@ end;
initial column widths and row heights.
-------------------------------------------------------------------------------}
procedure TsCustomWorksheetGrid.Setup;
var
nc, nr: Integer;
begin
if csLoading in ComponentState then
exit;
@ -4495,6 +4497,8 @@ begin
end;
end else
if Worksheet <> nil then begin
nc := ColCount;
nr := RowCount;
if FHeaderCount = 0 then
begin
ColCount := Max(GetGridCol(Worksheet.GetLastColIndex), ColCount-1);
@ -4811,7 +4815,7 @@ begin
if Worksheet <> nil then
begin
lCol := Worksheet.FindCol(i - FHeaderCount);
if lCol <> nil then
if (lCol <> nil) and (lCol^.ColWidthType = cwtCustom) then
w100 := CalcColWidthFromSheet(lCol^.Width)
else
w100 := CalcColWidthFromSheet(Worksheet.ReadDefaultColWidth(Workbook.Units));