fpspreadsheet: Write row/column hidden flag to XLSX, BIFF8 and BIFF2

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6632 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2018-09-05 23:04:49 +00:00
parent 6c92513d96
commit 02787a6947
3 changed files with 35 additions and 20 deletions

View File

@ -3904,6 +3904,7 @@ var
rec: TColRecord;
w: Integer;
width: Single;
optn: Word;
begin
if Assigned(ACol) then
begin
@ -3927,9 +3928,13 @@ begin
end;
w := round(width * 256);
optn := 0;
if ACol^.Hidden then optn := optn + $0001;
// outline, collapsed flags are not used
rec.ColWidth := WordToLE(w);
rec.XFIndex := WordToLE(FindXFIndex(ACol^.FormatIndex));// Index of XF record
rec.OptionFlags := 0; // hidden, outline, collapsed flags are not used
rec.XFIndex := WordToLE(FindXFIndex(ACol^.FormatIndex)); // Index of XF record
rec.OptionFlags := WordToLE(optn);
rec.NotUsed := 0;
{ Write out }
@ -4787,6 +4792,7 @@ begin
{ Option flags }
dw := $00000100; // bit 8 is always 1
if Assigned(ARow) and ARow^.Hidden then dw := dw or $00000020;
if spaceabove then dw := dw or $10000000;
if spacebelow then dw := dw or $20000000;
if (ARow <> nil) and (ARow^.RowHeightType = rhtCustom) then // Custom row height

View File

@ -2985,6 +2985,7 @@ var
customWidth: String;
customStyle: String;
sheet: TsWorksheet absolute AWorksheet;
hiddenStr: String;
begin
AppendToStream(AStream,
'<cols>');
@ -2996,6 +2997,7 @@ begin
// The column width is needed in suChars here.
w := sheet.ReadDefaultColWidth(suChars);
hiddenStr := '';
if lCol <> nil then begin
if lCol^.ColWidthType = cwtCustom then begin
w := (FWorkbook as TsWorkbook).ConvertUnits(lCol^.Width, FWorkbook.Units, suChars);
@ -3003,10 +3005,11 @@ begin
end;
if lCol^.FormatIndex > 0 then
customStyle := Format('style="%d" ', [lCol^.FormatIndex]);
if lCol^.Hidden then hiddenStr := ' hidden="1"';
end;
AppendToStream(AStream, Format(
'<col min="%d" max="%d" width="%.2f" %s%s />',
[c+1, c+1, w, customWidth, customStyle], FPointSeparatorSettings)
'<col min="%d" max="%d" width="%.2f" %s%s%s />',
[c+1, c+1, w, customWidth, customStyle, hiddenStr], FPointSeparatorSettings)
);
end;
@ -3457,6 +3460,8 @@ begin
s := s + ' customHeight="1"';
if row^.FormatIndex > 0 then
s := s + Format(' s="%d" customFormat="1"', [row^.FormatIndex]);
if row^.Hidden then
s := s + ' hidden="1"';
end;
AppendToStream(AStream, Format(
'<row r="%d" spans="1:%d"%s>', [r+1, sheet.VirtualColCount, s]));
@ -3522,6 +3527,8 @@ begin
s := s + ' customHeight="1"';
if row^.FormatIndex > 0 then
s := s + Format(' s="%d" customFormat="1"', [row^.FormatIndex]);
if row^.Hidden then
s := s + ' hidden="1"';
end;
AppendToStream(AStream, Format(
'<row r="%d" spans="%d:%d"%s>', [r+1, c1+1, c2+1, s]));

View File

@ -1444,12 +1444,15 @@ end;
has occured at the border of a row header. Sets optimum row height.
-------------------------------------------------------------------------------}
procedure TsCustomWorksheetGrid.AutoAdjustRow(ARow: Integer);
var
h: Integer;
begin
inc(FZoomLock);
if Worksheet <> nil then
RowHeights[ARow] := CalcAutoRowHeight(ARow)
h := CalcAutoRowHeight(ARow)
else
RowHeights[ARow] := DefaultRowHeight;
h := -1;
RowHeights[ARow] := IfThen(h > -1, h, DefaultRowHeight);
HeaderSized(false, ARow);
dec(FZoomLock);
end;
@ -1521,15 +1524,10 @@ end;
function TsCustomWorksheetGrid.CalcAutoRowHeight(ARow: Integer): Integer;
var
c: Integer;
h: Integer;
begin
h := 0;
Result := -1;
for c := FHeaderCount to ColCount-1 do
h := Max(h, GetCellHeight(c, ARow)); // Zoom factor is applied to font size
if h = 0 then
Result := DefaultRowHeight // Zoom factor applied by getter function
else
Result := h;
Result := Max(Result, GetCellHeight(c, ARow)); // Zoom factor is applied to font size
end;
{@@ ----------------------------------------------------------------------------
@ -1815,6 +1813,7 @@ procedure TsCustomWorksheetGrid.ChangedFontHandler(ASender: TObject;
var
lRow: PRow;
gr: Integer; // row index in grid units
h: Integer;
begin
Unused(ASender, ACol);
if (Worksheet <> nil) then begin
@ -1823,7 +1822,8 @@ begin
// There is no row record --> row height changes according to font height
// Otherwise the row height would be fixed according to the value in the row record.
gr := GetGridRow(ARow); // convert row index to grid units
RowHeights[gr] := CalcAutoRowHeight(gr);
h := CalcAutoRowHeight(gr);
RowHeights[gr] := IfThen(h > -1, h, DefaultRowHeight);
end;
Invalidate;
end;
@ -3745,7 +3745,7 @@ var
txtRot: TsTextRotation;
RTL: Boolean;
begin
Result := 0;
Result := -1;
if (ACol < FHeaderCount) or (ARow < FHeaderCount) then
exit;
if Worksheet = nil then
@ -5777,11 +5777,11 @@ begin
if (lRow <> nil) then begin
case lRow^.RowHeightType of
rhtCustom:
begin
if lRow^.Height > 0 then begin
h := round(CalcRowHeightFromSheet(lRow^.Height) * ZoomFactor);
if AEnforceCalcRowHeight then begin
h := CalcAutoRowHeight(ARow);
if h = 0 then begin
if h = -1 then begin
h := DefaultRowHeight;
lRow^.RowHeightType := rhtDefault;
end else
@ -5795,7 +5795,7 @@ begin
if doCalcRowHeight then begin
// Calculate current grid row height in pixels by iterating over all cells in row
h := CalcAutoRowHeight(ARow); // ZoomFactor already applied to font heights
if h = 0 then begin
if h = -1 then begin
h := DefaultRowHeight; // Zoom factor applied by getter function
lRow^.RowHeightType := rhtDefault;
end else
@ -5817,8 +5817,10 @@ begin
begin
// Case 1: This row does contain cells
lRow := Worksheet.AddRow(sr);
h := -1;
if AEnforceCalcRowHeight then
h := CalcAutoRowHeight(ARow) else
h := CalcAutoRowHeight(ARow);
if h = -1 then
h := DefaultRowHeight;
lRow^.Height := CalcRowHeightToSheet(round(h / ZoomFactor));
if h <> DefaultRowHeight then
@ -5830,7 +5832,7 @@ begin
h := DefaultRowHeight; // Zoom factor is applied by getter function
end;
if h = 0 then
if h = -1 then
h := DefaultRowHeight; // Zoom factor is applied by getter function
inc(FZoomLock); // We don't want to modify the sheet row heights here.