fpspreadsheet: Add reading of cell, sheet and workbook protection to biff2 and biff5.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5790 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2017-03-05 17:29:20 +00:00
parent 2f54a9bfca
commit b04fd3f0b5
5 changed files with 58 additions and 26 deletions

View File

@ -257,7 +257,7 @@ type
RecordSize: Word;
FontIndex: Byte;
NotUsed: Byte;
NumFormatIndex_Flags: Byte;
NumFormat_Prot: Byte;
HorAlign_Border_BkGr: Byte;
end;
@ -616,8 +616,10 @@ begin
INT_EXCEL_ID_NOTE : ReadComment(AStream);
INT_EXCEL_ID_NUMBER : ReadNumber(AStream);
INT_EXCEL_ID_PANE : ReadPane(AStream);
INT_EXCEL_ID_PASSWORD : ReadPASSWORD(AStream, FWorksheet);
INT_EXCEL_ID_PRINTGRID : ReadPrintGridLines(AStream);
INT_EXCEL_ID_PRINTHEADERS : ReadPrintHeaders(AStream);
INT_EXCEL_ID_PROTECT : ReadPROTECT(AStream, FWorksheet);
INT_EXCEL_ID_RIGHTMARGIN : ReadMargin(AStream, 1);
INT_EXCEL_ID_ROW : ReadRowInfo(AStream);
INT_EXCEL_ID_SELECTION : ReadSELECTION(AStream);
@ -625,6 +627,7 @@ begin
INT_EXCEL_ID_TOPMARGIN : ReadMargin(AStream, 2);
INT_EXCEL_ID_DEFROWHEIGHT : ReadDefRowHeight(AStream);
INT_EXCEL_ID_WINDOW2 : ReadWindow2(AStream);
INT_EXCEL_ID_WINDOWPROTECT : ReadWindowProtect(AStream);
INT_EXCEL_ID_XF : ReadXF(AStream);
else
// nothing
@ -1080,7 +1083,7 @@ begin
Include(fmt.UsedFormattingFields, uffFont);
// Number format index
b := rec.NumFormatIndex_Flags and $3F;
b := rec.NumFormat_Prot and $3F;
nfs := NumFormatList[b];
if nfs <> '' then
begin
@ -1132,6 +1135,15 @@ begin
Include(fmt.UsedFormattingFields, uffBackground);
end;
// Protection
b := rec.NumFormat_Prot and $C0;
case b of
$00: fmt.Protection := [];
$40: fmt.Protection := [cpLockCell];
$80: fmt.Protection := [cpHideFormulas];
$C0: fmt.Protection := [cpLockCell, cpHideFormulas];
end;
// Add the decoded data to the format list
FCellFormatList.Add(fmt);
end;
@ -1708,7 +1720,7 @@ begin
5-0 $3F Index to (number) FORMAT record
6 $40 1 = Cell is locked
7 $80 1 = Formula is hidden }
rec.NumFormatIndex_Flags := WordToLE(formatIdx);
rec.NumFormat_Prot := WordToLE(formatIdx);
// Cell flags not used, so far...
{Horizontal alignment, border style, and background

View File

@ -472,12 +472,15 @@ begin
INT_EXCEL_ID_BOUNDSHEET : ReadBoundSheet(AStream);
INT_EXCEL_ID_CODEPAGE : ReadCodePage(AStream);
INT_EXCEL_ID_DEFINEDNAME : ReadDefinedName(AStream);
INT_EXCEL_ID_EOF : SectionEOF := True;
INT_EXCEL_ID_EXTERNSHEET : ReadExternSheet(AStream);
INT_EXCEL_ID_FONT : ReadFont(AStream);
INT_EXCEL_ID_FORMAT : ReadFormat(AStream);
INT_EXCEL_ID_XF : ReadXF(AStream);
INT_EXCEL_ID_PALETTE : ReadPalette(AStream);
INT_EXCEL_ID_EOF : SectionEOF := True;
INT_EXCEL_ID_PASSWORD : ReadPASSWORD(AStream);
INT_EXCEL_ID_PROTECT : ReadPROTECT(AStream);
INT_EXCEL_ID_XF : ReadXF(AStream);
INT_EXCEL_ID_WINDOWPROTECT : ReadWindowProtect(AStream);
else
// nothing
end;
@ -533,8 +536,10 @@ begin
INT_EXCEL_ID_NUMBER : ReadNumber(AStream);
INT_EXCEL_ID_PANE : ReadPane(AStream);
INT_EXCEL_ID_PAGESETUP : ReadPageSetup(AStream);
INT_EXCEL_ID_PASSWORD : ReadPASSWORD(AStream, FWorksheet);
INT_EXCEL_ID_PRINTGRID : ReadPrintGridLines(AStream);
INT_EXCEL_ID_PRINTHEADERS : ReadPrintHeaders(AStream);
INT_EXCEL_ID_PROTECT : ReadPROTECT(AStream, FWorksheet);
INT_EXCEL_ID_RIGHTMARGIN : ReadMargin(AStream, 1);
INT_EXCEL_ID_RK : ReadRKValue(AStream); //(RK) This record represents a cell that contains an RK value (encoded integer or floating-point value). If a floating-point value cannot be encoded to an RK value, a NUMBER record will be written. This record replaces the record INTEGER written in BIFF2.
INT_EXCEL_ID_ROW : ReadRowInfo(AStream);
@ -900,6 +905,18 @@ begin
end;
end;
// Protection
case WordLEToN(rec.XFType_Prot_ParentXF) and MASK_XF_TYPE_PROTECTION of
0:
fmt.Protection := [];
MASK_XF_TYPE_PROT_LOCKED:
fmt.Protection := [cpLockCell];
MASK_XF_TYPE_PROT_FORMULA_HIDDEN:
fmt.Protection := [cpHideFormulas];
MASK_XF_TYPE_PROT_LOCKED + MASK_XF_TYPE_PROT_FORMULA_HIDDEN:
fmt.Protection := [cpLockCell, cpHideFormulas];
end;
// Add the XF to the list
FCellFormatList.Add(fmt);
end;

View File

@ -368,9 +368,6 @@ const
{ XF CELL BACKGROUND PATTERN }
MASK_XF_BACKGROUND_PATTERN = $FC000000;
{ XP CELL PROTECTION }
MASK_XF_PROTECTION = $0007;
{ HLINK FLAGS }
MASK_HLINK_LINK = $00000001;
MASK_HLINK_ABSOLUTE = $00000002;
@ -881,9 +878,9 @@ begin
INT_EXCEL_ID_PAGESETUP : ReadPageSetup(AStream);
INT_EXCEL_ID_PANE : ReadPane(AStream);
INT_EXCEL_ID_PASSWORD : ReadPASSWORD(AStream, FWorksheet);
INT_EXCEL_ID_PROTECT : ReadPROTECT(AStream, FWorksheet);
INT_EXCEL_ID_PRINTGRID : ReadPrintGridLines(AStream);
INT_EXCEL_ID_PRINTHEADERS : ReadPrintHeaders(AStream);
INT_EXCEL_ID_PROTECT : ReadPROTECT(AStream, FWorksheet);
INT_EXCEL_ID_RIGHTMARGIN : ReadMargin(AStream, 1);
INT_EXCEL_ID_ROW : ReadRowInfo(AStream);
@ -1687,11 +1684,15 @@ begin
end;
// Protection
case WordLEToN(rec.XFType_Prot_ParentXF) and MASK_XF_PROTECTION of
0: fmt.Protection := [];
1: fmt.Protection := [cpLockCell];
2: fmt.Protection := [cpHideFormulas];
3: fmt.Protection := [cpLockCell, cpHideFormulas];
case WordLEToN(rec.XFType_Prot_ParentXF) and MASK_XF_TYPE_PROTECTION of
0:
fmt.Protection := [];
MASK_XF_TYPE_PROT_LOCKED:
fmt.Protection := [cpLockCell];
MASK_XF_TYPE_PROT_FORMULA_HIDDEN:
fmt.Protection := [cpHideFormulas];
MASK_XF_TYPE_PROT_LOCKED + MASK_XF_TYPE_PROT_FORMULA_HIDDEN:
fmt.Protection := [cpLockCell, cpHideFormulas];
end;
// Add the XF to the internal cell format list

View File

@ -131,9 +131,11 @@ const
{ XF substructures }
{ XF_TYPE_PROT - XF Type and Cell protection (3 Bits) - BIFF3-BIFF8 }
MASK_XF_TYPE_PROT_LOCKED = $1;
MASK_XF_TYPE_PROT_FORMULA_HIDDEN = $2;
MASK_XF_TYPE_PROT_STYLE_XF = $4; // 0 = CELL XF
MASK_XF_TYPE_PROT_LOCKED = $0001;
MASK_XF_TYPE_PROT_FORMULA_HIDDEN = $0002;
MASK_XF_TYPE_PROT_STYLE_XF = $0004; // 0 = CELL XF
MASK_XF_TYPE_PROTECTION = $0007;
{ XF_USED_ATTRIB - Attributes from parent Style XF (6 Bits) - BIFF3-BIFF8

View File

@ -3362,7 +3362,7 @@ begin
GetEnumName(TypeInfo(TsBiDiMode), ord(fmt.BiDiMode))]));
if (AFormatIndex = -1) then
AStrings.Add('Protection=(not protected)')
AStrings.Add('Protection=(default)')
else begin
if Worksheet.IsProtected then begin
s := '';