fpspreadsheet: Fix unit conversion error in colwidth calculation. CopyWorksheetFrom() now copies also DefaultFont and DefaultColWidth

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7529 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-07-08 17:56:08 +00:00
parent 80a3750dbd
commit 9a4f358ae2
2 changed files with 19 additions and 1 deletions

View File

@@ -9267,6 +9267,8 @@ var
col: PCol; col: PCol;
row: PRow; row: PRow;
i: Integer; i: Integer;
w: Single;
fnt: TsFont;
begin begin
Result := nil; Result := nil;
if (AWorksheet = nil) then if (AWorksheet = nil) then
@@ -9275,18 +9277,34 @@ begin
Result := AddWorksheet(AWorksheet.Name, ReplaceDuplicateName); Result := AddWorksheet(AWorksheet.Name, ReplaceDuplicateName);
inc(FNotificationLock); inc(FNotificationLock);
try try
// Make sure to use the same default font, colwidths depend on it!
if Result.WorkBook <> AWorksheet.Workbook then
begin
fnt := AWorksheet.Workbook.GetDefaultFont;
Result.Workbook.SetDefaultFont(fnt.FontName, fnt.Size);
end;
// Copy DefaultColWidth
w := AWorksheet.ReadDefaultColWidth(suMillimeters);
Result.WriteDefaultColWidth(w, suMillimeters);
// Copy cells (incl formulas, comments, hyperlinks etc).
for cell in AWorksheet.Cells do for cell in AWorksheet.Cells do
begin begin
r := cell^.Row; r := cell^.Row;
c := cell^.Col; c := cell^.Col;
Result.CopyCell(r, c, r, c, AWorksheet); Result.CopyCell(r, c, r, c, AWorksheet);
end; end;
// Copy col records
for i := 0 to AWorksheet.Cols.Count-1 do for i := 0 to AWorksheet.Cols.Count-1 do
begin begin
col := AWorksheet.Cols[i]; col := AWorksheet.Cols[i];
c := col^.Col; c := col^.Col;
Result.CopyCol(c, c, AWorksheet); Result.CopyCol(c, c, AWorksheet);
end; end;
// Copy row records
for i := 0 to AWorksheet.Rows.Count-1 do for i := 0 to AWorksheet.Rows.Count-1 do
begin begin
row := AWorksheet.Rows[i]; row := AWorksheet.Rows[i];

View File

@@ -422,7 +422,7 @@ begin
if lCol^.ColWidthType = cwtCustom then if lCol^.ColWidthType = cwtCustom then
w0 := lCol^.Width w0 := lCol^.Width
else else
w0 := sheet.DefaultColWidth; w0 := sheet.ReadDefaultColWidth(sheet.Workbook.Units);
// w := PCol(sheet.Cols[0])^.Width; // w := PCol(sheet.Cols[0])^.Width;
for c := 1 to sheet.Cols.Count-1 do begin for c := 1 to sheet.Cols.Count-1 do begin
lCol := PCol(sheet.Cols[c]); lCol := PCol(sheet.Cols[c]);