You've already forked lazarus-ccr
fpspreadsheet: Ignore filler columns added by Calc when reading an Excel file.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5269 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -323,29 +323,55 @@ procedure TsCustomSpreadReader.FixCols(AWorkSheet: TsWorksheet);
|
|||||||
const
|
const
|
||||||
EPS = 1E-3;
|
EPS = 1E-3;
|
||||||
var
|
var
|
||||||
c: Cardinal;
|
c: LongInt;
|
||||||
w: Single;
|
w: Single;
|
||||||
lCol: PCol;
|
lCol: PCol;
|
||||||
|
sameWidth: Boolean;
|
||||||
begin
|
begin
|
||||||
|
// If the count of columns is equal to the max colcount of the file format
|
||||||
|
// then it is likely that dummy columns have been added -> delete all empty
|
||||||
|
// columns (starting at the right) until the first non-empty column is found
|
||||||
|
if AWorksheet.Cols.Count = FLimitations.MaxColCount then
|
||||||
|
begin
|
||||||
|
c := AWorksheet.Cols.Count - 1;
|
||||||
|
lCol := PCol(AWorksheet.Cols[c]);
|
||||||
|
w := lCol.Width;
|
||||||
|
while c >= 0 do begin
|
||||||
|
lCol := PCol(AWorksheet.Cols[c]);
|
||||||
|
if not SameValue(lCol^.Width, w, EPS) then
|
||||||
|
break;
|
||||||
|
if AWorksheet.FindNextCellInCol(0, c) <> nil then
|
||||||
|
break;
|
||||||
|
AWorksheet.RemoveCol(c);
|
||||||
|
dec(c);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
if AWorksheet.Cols.Count < 2 then
|
if AWorksheet.Cols.Count < 2 then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
// Check whether all columns have the same column width
|
// Check whether all columns have the same column width
|
||||||
|
sameWidth := true;
|
||||||
w := PCol(AWorksheet.Cols[0])^.Width;
|
w := PCol(AWorksheet.Cols[0])^.Width;
|
||||||
for c := 1 to AWorksheet.Cols.Count-1 do begin
|
for c := 1 to AWorksheet.Cols.Count-1 do begin
|
||||||
lCol := PCol(AWorksheet.Cols[c]);
|
lCol := PCol(AWorksheet.Cols[c]);
|
||||||
if not SameValue(lCol^.Width, w, EPS) then
|
if not SameValue(lCol^.Width, w, EPS) then
|
||||||
exit;
|
begin
|
||||||
|
sameWidth := false;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// At this point we know that all columns have the same width. We pass this
|
if sameWidth then begin
|
||||||
// to the DefaultColWidth ...
|
// At this point we know that all columns have the same width. We pass this
|
||||||
AWorksheet.WriteDefaultColWidth(w, FWorkbook.Units);
|
// to the DefaultColWidth ...
|
||||||
|
AWorksheet.WriteDefaultColWidth(w, FWorkbook.Units);
|
||||||
|
|
||||||
// ...and delete all column records with non-default format
|
// ...and delete all column records with non-default format
|
||||||
for c := AWorksheet.Cols.Count-1 downto 0 do begin
|
for c := AWorksheet.Cols.Count-1 downto 0 do begin
|
||||||
lCol := PCol(AWorksheet.Cols[c]);
|
lCol := PCol(AWorksheet.Cols[c]);
|
||||||
if lCol^.FormatIndex = 0 then AWorksheet.RemoveCol(c);
|
if lCol^.FormatIndex = 0 then AWorksheet.RemoveCol(c);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -1129,7 +1129,7 @@ begin
|
|||||||
fail('Error in test code. Failed to get named worksheet');
|
fail('Error in test code. Failed to get named worksheet');
|
||||||
for Col := Low(SollColWidths) to High(SollColWidths) do
|
for Col := Low(SollColWidths) to High(SollColWidths) do
|
||||||
begin
|
begin
|
||||||
lpCol := MyWorksheet.GetCol(Col);
|
lpCol := MyWorksheet.FindCol(Col);
|
||||||
if lpCol = nil then
|
if lpCol = nil then
|
||||||
fail('Error in test code. Failed to return saved column width');
|
fail('Error in test code. Failed to return saved column width');
|
||||||
ActualColWidth := MyWorkbook.ConvertUnits(lpCol^.Width, MyWorkbook.Units, suChars);
|
ActualColWidth := MyWorkbook.ConvertUnits(lpCol^.Width, MyWorkbook.Units, suChars);
|
||||||
|
Reference in New Issue
Block a user