From e3d40d489f8f97a27c5bf70e0f7b07dc579e8c56 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sun, 19 Mar 2017 23:10:55 +0000 Subject: [PATCH] spready: Use decrypting xlsx reader. Add cell and worksheet protection. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5814 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- applications/spready/fpssylk.pas | 7 +- applications/spready/smain.lfm | 127 +++++++++++++----- applications/spready/smain.pas | 55 +++++++- applications/spready/spready.lpi | 21 ++- applications/spready/spready.lpr | 2 +- applications/spready/sworksheetprotection.lfm | 103 ++++++++++++++ applications/spready/sworksheetprotection.pas | 87 ++++++++++++ 7 files changed, 356 insertions(+), 46 deletions(-) create mode 100644 applications/spready/sworksheetprotection.lfm create mode 100644 applications/spready/sworksheetprotection.pas diff --git a/applications/spready/fpssylk.pas b/applications/spready/fpssylk.pas index 1301cfeae..5531a113d 100644 --- a/applications/spready/fpssylk.pas +++ b/applications/spready/fpssylk.pas @@ -31,7 +31,8 @@ type procedure ProcessRecord(ARecordType: String; const AFields: TsSYLKFields); public constructor Create(AWorkbook: TsWorkbook); override; - procedure ReadFromFile(AFileName: String; AParams: TsStreamParams = []); override; + procedure ReadFromFile(AFileName: String; APassword: String = ''; + AParams: TsStreamParams = []); override; procedure ReadFromStrings(AStrings: TStrings; AParams: TsStreamParams = []); override; end; @@ -335,10 +336,10 @@ begin end; procedure TsSYLKReader.ReadFromFile(AFileName: String; - AParams: TsStreamParams = []); + APassword: String = ''; AParams: TsStreamParams = []); begin FWorksheetName := ChangeFileExt(ExtractFileName(AFileName), ''); - inherited ReadFromFile(AFilename, AParams); + inherited ReadFromFile(AFilename, APassword, AParams); end; procedure TsSYLKReader.ReadFromStrings(AStrings: TStrings; diff --git a/applications/spready/smain.lfm b/applications/spready/smain.lfm index 6490caab4..43270875f 100644 --- a/applications/spready/smain.lfm +++ b/applications/spready/smain.lfm @@ -1,7 +1,7 @@ object MainForm: TMainForm - Left = 267 + Left = 265 Height = 709 - Top = 152 + Top = 139 Width = 1120 Caption = 'spready' ClientHeight = 689 @@ -37,7 +37,6 @@ object MainForm: TMainForm WorkbookSource = WorkbookSource Align = alClient AutoAdvance = aaDown - ColCount = 27 DefaultColWidth = 64 DefaultRowHeight = 22 Font.Color = clBlack @@ -46,7 +45,6 @@ object MainForm: TMainForm MouseWheelOption = mwGrid Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSizing, goColSizing, goEditing, goThumbTracking, goDblClickAutoSize, goCellHints] ParentFont = False - RowCount = 101 TabOrder = 1 TitleFont.Color = clBlack TitleFont.Height = -13 @@ -83,7 +81,7 @@ object MainForm: TMainForm Align = alClient DefaultColWidth = 100 MouseWheelOption = mwGrid - RowCount = 33 + RowCount = 39 TabOrder = 1 TitleStyle = tsNative OnEnter = InspectorEnter @@ -101,8 +99,8 @@ object MainForm: TMainForm ' ListSeparator=;' ' DateSeparator=.' ' TimeSeparator=:' - ' ShortDateFormat=dd.MM.yy' - ' LongDateFormat=dd.MMM.yyyy' + ' ShortDateFormat=dd.MM.yyyy' + ' LongDateFormat=dddd, d. MMMM yyyy' ' ShortTimeFormat=hh:nn' ' LongTimeFormat=hh:nn:ss' ' TimeAMString=' @@ -123,6 +121,12 @@ object MainForm: TMainForm ' Font3=Arial; size 10; black; italic' '(-) Cell formats=' ' CellFormat0=nfGeneral' + 'Protection=(default)' + '(-) CryptoInfo=' + ' PasswordHash=' + ' Algorithm=' + ' SaltValue=' + ' SpinCount=0' ) TitleCaptions.Strings = ( 'Properties' @@ -177,7 +181,6 @@ object MainForm: TMainForm Left = 376 Height = 26 Top = 0 - Width = 5 Caption = 'ToolButton10' Style = tbsDivider end @@ -205,7 +208,6 @@ object MainForm: TMainForm Left = 453 Height = 26 Top = 0 - Width = 5 Caption = 'ToolButton15' Style = tbsDivider end @@ -228,7 +230,6 @@ object MainForm: TMainForm Left = 530 Height = 26 Top = 0 - Width = 5 Caption = 'ToolButton19' Style = tbsDivider end @@ -254,14 +255,6 @@ object MainForm: TMainForm Top = 0 Action = AcNumFormatPercentage end - object ToolButton23: TToolButton - Left = 896 - Height = 26 - Top = 0 - Width = 5 - Caption = 'ToolButton23' - Style = tbsDivider - end object ToolButton24: TToolButton Left = 660 Top = 0 @@ -304,7 +297,6 @@ object MainForm: TMainForm Left = 855 Height = 26 Top = 0 - Width = 5 Caption = 'ToolButton31' Style = tbsDivider end @@ -321,12 +313,11 @@ object MainForm: TMainForm Left = 780 Height = 26 Top = 0 - Width = 5 Caption = 'ToolButton3' Style = tbsDivider end object ToolButton5: TToolButton - Left = 901 + Left = 896 Top = 0 Action = AcMergeCells end @@ -344,7 +335,6 @@ object MainForm: TMainForm Left = 25 Height = 26 Top = 0 - Width = 5 Caption = 'ToolButton38' Style = tbsDivider end @@ -408,10 +398,24 @@ object MainForm: TMainForm Left = 559 Height = 26 Top = 0 - Width = 5 Caption = 'ToolButton45' Style = tbsDivider end + object ToolButton56: TToolButton + Left = 920 + Height = 26 + Top = 0 + Caption = 'ToolButton56' + Style = tbsDivider + end + object ToolButton58: TToolButton + Left = 925 + Top = 0 + Caption = 'ToolButton58' + DropdownMenu = PuCellProtection + ImageIndex = 73 + Style = tbsButtonDrop + end end object ToolBar2: TToolBar Left = 0 @@ -444,7 +448,6 @@ object MainForm: TMainForm Left = 357 Height = 24 Top = 0 - Width = 5 Caption = 'ToolButton1' Style = tbsDivider end @@ -464,7 +467,6 @@ object MainForm: TMainForm Left = 251 Height = 24 Top = 0 - Width = 5 Caption = 'ToolButton28' Style = tbsDivider end @@ -497,7 +499,6 @@ object MainForm: TMainForm Left = 174 Height = 24 Top = 0 - Width = 5 Caption = 'ToolButton43' Style = tbsDivider end @@ -505,7 +506,6 @@ object MainForm: TMainForm Left = 304 Height = 24 Top = 0 - Width = 5 Caption = 'ToolButton44' Style = tbsDivider end @@ -530,7 +530,6 @@ object MainForm: TMainForm Left = 85 Height = 24 Top = 0 - Width = 5 Caption = 'ToolButton49' Style = tbsDivider end @@ -553,7 +552,6 @@ object MainForm: TMainForm Left = 434 Height = 24 Top = 0 - Width = 5 Caption = 'ToolButton52' Style = tbsDivider end @@ -576,7 +574,6 @@ object MainForm: TMainForm Left = 511 Height = 24 Top = 0 - Width = 5 Caption = 'ToolButton54' Style = tbsDivider end @@ -589,7 +586,6 @@ object MainForm: TMainForm Left = 540 Height = 24 Top = 0 - Width = 5 Caption = 'ToolButton55' Style = tbsDivider end @@ -624,10 +620,10 @@ object MainForm: TMainForm Height = 23 Top = 0 Width = 138 + WorkbookSource = WorkbookSource Align = alTop TabOrder = 0 Text = 'A1' - WorkbookSource = WorkbookSource end end object CellEdit: TsCellEdit @@ -1892,12 +1888,30 @@ object MainForm: TMainForm Hint = 'Set width of current column' OnExecute = AcColWidthExecute end + object AcCellProtection_Cell: TsCellProtectionAction + Category = 'FPSpreadsheet' + WorkbookSource = WorkbookSource + Caption = 'Protect cell' + end + object AcCellProtection_HideFormulas: TsCellProtectionAction + Category = 'FPSpreadsheet' + WorkbookSource = WorkbookSource + Caption = 'Hide formulas' + Protection = cpHideFormulas + end + object AcWorksheetProtection: TAction + Category = 'Worksheet' + Caption = 'Protect worksheet...' + ImageIndex = 73 + OnExecute = AcWorksheetProtectionExecute + OnUpdate = AcWorksheetProtectionUpdate + end end object ImageList: TImageList left = 176 top = 312 Bitmap = { - 4C69490000001000000010000000003F9300003F9300003F9300003F9424003F + 4C694A0000001000000010000000003F9300003F9300003F9300003F9424003F 948A003E93CC004095CC004095CC004095CC004095CC004095CC004095CC0040 95CC004095CC00409599003F9400003F9300003F9324003F938A0E4B9CD33F76 C0EC5D90D4FF3365A9FFA0A0A0FFA9A9A9FFA9A9A9FFAAAAAAFFACACACFFAEAE @@ -4233,6 +4247,38 @@ object MainForm: TMainForm 001A7205006B720500A5720500C3720500C3720500A57205006B7506001A800E 010090170200951A0200FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF + FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF + FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF + FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF000278B3000278B300037A + B6000380BE330380BF720380BF890380BF890380BF720380BE33037AB6000278 + B3000278B300FFFFFF00FFFFFF00FFFFFF00FFFFFF000278B3000278B3000379 + B5351D8CC29B7ECDEBE16AB5D1EA6AB5D1EA7ECDEBE11D8CC29B0379B5350278 + B3000278B300FFFFFF00FFFFFF00FFFFFF00FFFFFF000272AA000272AA000272 + AA7A7CC8E7E6388AB2D5015B8891015B8891388AB2D57CC8E7E60272AA7A0272 + AA000272AA00FFFFFF00FFFFFF00FFFFFF00FFFFFF000376B00002699D000269 + 9D9784C9E6FD066594B9015F8E00015F8E00066594B984C9E6FD02699D970269 + 9D000375AE00FFFFFF00FFFFFF00FFFFFF00FFFFFF000381BF000377B1000160 + 90A376BADBFF016494B201689A00015A8700016494B278BCDDFF016090A30272 + AA00037EBB00FFFFFF00FFFFFF00FFFFFF00FFFFFF000381BF69037DBA8F0059 + 86A865AACCFF016698AD01699CA9005783CA016698AD4B91B5FF005986A80276 + B09B037EBB6DFFFFFF00FFFFFF00FFFFFF00FFFFFF000381BF8BA5E9FFFF9CDF + FAFF94D7F4FF8CCEEEFF83C7E8FF5EB4D7FF5EBADEFF5EC2E8FF5ECAF2FF62D6 + FBFF037EBB90FFFFFF00FFFFFF00FFFFFF00FFFFFF000381BF8B66AACAFF68AC + CEFF6CB0D2FF6EB1D3FF6AAED0FF559DBFFF55A0C2FF55A5CAFF55ABD3FF5AB8 + DEFF037EBB90FFFFFF00FFFFFF00FFFFFF00FFFFFF000381BF8BA5E9FFFF9CDF + FAFF94D7F4FF8CCEEEFF83C7E8FF5EB4D7FF5EBADEFF5EC2E8FF5ECAF2FF62D6 + FBFF037EBB90FFFFFF00FFFFFF00FFFFFF00FFFFFF00037DBA8A66AACAFF68AC + CEFF6CB0D2FF6EB1D3FF6AAED0FF559DBFFF55A0C2FF55A5CAFF55ABD3FF5AB8 + DEFF037AB68FFFFFFF00FFFFFF00FFFFFF00FFFFFF0002669F87A5E9FFFF9CDF + FAFF94D7F4FF8CCEEEFF83C7E8FF5EB4D7FF5EBADEFF5EC2E8FF5ECAF2FF62D6 + FBFF02659C8AFFFFFF00FFFFFF00FFFFFF00FFFFFF00014B7C8D66AACAFF68AC + CEFF6CB0D2FF6EB1D3FF6AAED0FF559DBFFF55A0C2FF55A5CAFF55ABD3FF5AB8 + DEFF014A7B8FFFFFFF00FFFFFF00FFFFFF00FFFFFF00013763A0A9EDFFFFA4E7 + FCFF9CDFF8FF94D6F4FF8BCFF0FF66BCDEFF66C2E4FF66CAECFF66D2F4FF66DA + FCFF013763A0FFFFFF00FFFFFF00FFFFFF00FFFFFF00002C5695002F5AB30037 + 649E0146769301578895016294A2002D57BD002D57BC002D57BC002D58BC002D + 58BC002E598BFFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF + FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF FF00FFFFFF00FFFFFF00FFFFFF00 } end @@ -4314,6 +4360,9 @@ object MainForm: TMainForm object MenuItem160: TMenuItem Action = acRenameWorksheet end + object MenuItem106: TMenuItem + Action = AcWorksheetProtection + end object MenuItem165: TMenuItem Caption = '-' end @@ -4866,4 +4915,16 @@ object MainForm: TMainForm left = 504 top = 536 end + object PuCellProtection: TPopupMenu + left = 504 + top = 600 + object MenuItem104: TMenuItem + Action = AcCellProtection_Cell + AutoCheck = True + end + object MenuItem105: TMenuItem + Action = AcCellProtection_HideFormulas + AutoCheck = True + end + end end diff --git a/applications/spready/smain.pas b/applications/spready/smain.pas index fb3a55c36..14f2896ab 100644 --- a/applications/spready/smain.pas +++ b/applications/spready/smain.pas @@ -6,9 +6,12 @@ interface uses Classes, SysUtils, FileUtil, mrumanager, Forms, Controls, Graphics, Dialogs, - ExtCtrls, ComCtrls, ActnList, Menus, StdActns, Buttons, fpstypes, - fpspreadsheet, fpspreadsheetctrls, fpspreadsheetgrid, fpsActions, - fpsSYLK, xlsxml, Grids, Types; + ExtCtrls, ComCtrls, ActnList, Menus, StdActns, Buttons, Grids, types, + fpstypes, fpspreadsheet, fpspreadsheetctrls, fpspreadsheetgrid, fpsActions, + fpsAllFormats, fpsSYLK, xlsxml, xlsxooxml_crypto; + // NOTE: + // In order to use the decrypting xlsx reader put xlsxooxlm_cryto after + // xlsxooxml or fpsAllforamts. type @@ -34,6 +37,7 @@ type AcSortColAsc: TAction; AcRowHeight: TAction; AcColWidth: TAction; + AcWorksheetProtection: TAction; AcWorksheetRTL: TAction; AcViewInspector: TAction; ActionList: TActionList; @@ -45,6 +49,9 @@ type MenuItem1: TMenuItem; MenuItem102: TMenuItem; MenuItem103: TMenuItem; + MenuItem104: TMenuItem; + MenuItem105: TMenuItem; + MenuItem106: TMenuItem; MenuItem160: TMenuItem; MenuItem161: TMenuItem; MenuItem162: TMenuItem; @@ -244,6 +251,7 @@ type AcNumFormatCurrency: TsNumberFormatAction; AcNumFormatCurrencyRed: TsNumberFormatAction; Panel2: TPanel; + PuCellProtection: TPopupMenu; PuRecentFiles: TPopupMenu; PuPaste: TPopupMenu; PuBorders: TPopupMenu; @@ -308,6 +316,8 @@ type AcCellBorderDiagUp: TsCellBorderAction; AcCellBorderDiagDown: TsCellBorderAction; AcNumFormatText: TsNumberFormatAction; + AcCellProtection_Cell: TsCellProtectionAction; + AcCellProtection_HideFormulas: TsCellProtectionAction; Splitter2: TSplitter; Splitter3: TSplitter; AcZoom100: TsWorksheetZoomAction; @@ -345,7 +355,6 @@ type ToolButton20: TToolButton; ToolButton21: TToolButton; ToolButton22: TToolButton; - ToolButton23: TToolButton; ToolButton24: TToolButton; ToolButton25: TToolButton; ToolButton26: TToolButton; @@ -385,6 +394,8 @@ type ToolButton53: TToolButton; ToolButton54: TToolButton; ToolButton55: TToolButton; + ToolButton56: TToolButton; + ToolButton58: TToolButton; ToolButton6: TToolButton; ToolButton7: TToolButton; ToolButton8: TToolButton; @@ -414,6 +425,8 @@ type procedure AcSortColAscExecute(Sender: TObject); procedure AcSortExecute(Sender: TObject); procedure ActionListUpdate(AAction: TBasicAction; var Handled: Boolean); + procedure AcWorksheetProtectionExecute(Sender: TObject); + procedure AcWorksheetProtectionUpdate(Sender: TObject); procedure AcWorksheetRTLExecute(Sender: TObject); procedure AcWorksheetRTLUpdate(Sender: TObject); procedure AcSearchExecute(Sender: TObject); @@ -473,7 +486,7 @@ uses fpsUtils, fpsCSV, fpsReaderWriter, sCSVParamsForm, sCurrencyForm, sFormatSettingsForm, sSortParamsForm, sHyperlinkForm, sNumFormatForm, sSearchForm, sColWidthForm, sRowHeightForm, - sAbout; + sWorksheetProtection, sAbout; var SEARCH_DLG_POS: TPoint = (X: -1; Y: -1); @@ -866,6 +879,34 @@ begin UpdateInspectorColumns; end; +procedure TMainForm.AcWorksheetProtectionExecute(Sender: TObject); +var + F: TWorksheetProtectionForm; +begin + if WorkbookSource.Worksheet.IsProtected then + WorkbookSource.Worksheet.Protect(false) + else + begin + F := TWorksheetProtectionForm.Create(nil); + try + F.IsProtected := WorkbookSource.Worksheet.IsProtected; + F.Protection := WorkbookSource.Worksheet.Protection; + if F.ShowModal = mrOK then + begin + WorkbookSource.Worksheet.Protection := F.Protection; + WorkbookSource.Worksheet.Protect(F.IsProtected); + end; + finally + F.Free; + end; + end; +end; + +procedure TMainForm.AcWorksheetProtectionUpdate(Sender: TObject); +begin + AcWorksheetProtection.Checked := WorkbookSource.Worksheet.IsProtected; +end; + procedure TMainForm.BeforeRun; begin ReadFromIni; @@ -945,6 +986,7 @@ end; procedure TMainForm.FormCreate(Sender: TObject); var priorityFormats: Array[0..8] of TsSpreadFormatID; + i: Integer; begin FMRUMenuManager := TMRUMenuManager.Create(self); with FMRUMenuManager do begin @@ -970,6 +1012,9 @@ begin AcFileOpen.Dialog.Filter := GetFileFormatFilter('|', ';', faRead, priorityFormats, true, true); FOpenFormats := GetSpreadFormats(faRead, priorityFormats); + // Use decrypting XLSX format instead of normal XLSX format + for i:=0 to High(FOpenFormats) do + if FOpenFormats[i] = ord(sfOOXML) then FOpenFormats[i] := sfidOOXML_Crypto; AcFileSaveAs.Dialog.Filter := GetFileFormatFilter('|', ';', faWrite, priorityFormats); FSaveFormats := GetSpreadFormats(faWrite, priorityFormats); diff --git a/applications/spready/spready.lpi b/applications/spready/spready.lpi index 973887c2d..a883f0d98 100644 --- a/applications/spready/spready.lpi +++ b/applications/spready/spready.lpi @@ -57,15 +57,18 @@ - + - + - + + + + - + @@ -89,7 +92,9 @@ + + @@ -154,6 +159,14 @@ + + + + + + + + diff --git a/applications/spready/spready.lpr b/applications/spready/spready.lpr index 5770ecb98..4387b0517 100644 --- a/applications/spready/spready.lpr +++ b/applications/spready/spready.lpr @@ -7,7 +7,7 @@ uses cthreads, {$ENDIF}{$ENDIF} Interfaces, // this includes the LCL widgetset - Forms, smain, sColWidthForm; + Forms, smain, sColWidthForm, sWorksheetProtection; {$R *.res} diff --git a/applications/spready/sworksheetprotection.lfm b/applications/spready/sworksheetprotection.lfm new file mode 100644 index 000000000..6dfda782a --- /dev/null +++ b/applications/spready/sworksheetprotection.lfm @@ -0,0 +1,103 @@ +object WorksheetProtectionForm: TWorksheetProtectionForm + Left = 280 + Height = 153 + Top = 130 + Width = 316 + BorderStyle = bsDialog + Caption = 'Worksheet protection' + ClientHeight = 153 + ClientWidth = 316 + OnCreate = FormCreate + Position = poMainFormCenter + LCLVersion = '1.7' + object ButtonPanel: TButtonPanel + Left = 6 + Height = 34 + Top = 113 + Width = 304 + BorderSpacing.Top = 8 + OKButton.Name = 'OKButton' + OKButton.DefaultCaption = True + HelpButton.Name = 'HelpButton' + HelpButton.DefaultCaption = True + CloseButton.Name = 'CloseButton' + CloseButton.DefaultCaption = True + CancelButton.Name = 'CancelButton' + CancelButton.DefaultCaption = True + TabOrder = 0 + ShowButtons = [pbOK, pbCancel] + end + object CbProtect: TCheckBox + Left = 8 + Height = 19 + Top = 8 + Width = 308 + Align = alTop + BorderSpacing.Left = 8 + BorderSpacing.Top = 8 + BorderSpacing.Bottom = 8 + Caption = 'Protect worksheet and locked cells' + OnChange = CbProtectChange + TabOrder = 1 + end + object LblProtectionItems: TLabel + Left = 8 + Height = 15 + Top = 46 + Width = 300 + Align = alTop + BorderSpacing.Left = 8 + BorderSpacing.Top = 8 + BorderSpacing.Right = 8 + BorderSpacing.Bottom = 4 + Caption = 'All users of this worksheet are allowed to' + ParentColor = False + end + object TopBevel: TBevel + Left = 8 + Height = 3 + Top = 35 + Width = 300 + Align = alTop + BorderSpacing.Left = 8 + BorderSpacing.Right = 8 + Shape = bsTopLine + end + object ItemsPanel: TPanel + Left = 0 + Height = 38 + Top = 65 + Width = 316 + Align = alTop + BevelOuter = bvNone + ClientHeight = 38 + ClientWidth = 316 + TabOrder = 2 + object CbSelectLockedCells: TCheckBox + Left = 8 + Height = 19 + Top = 0 + Width = 300 + Align = alTop + BorderSpacing.Left = 8 + BorderSpacing.Right = 8 + Caption = 'select locked cells' + Checked = True + State = cbChecked + TabOrder = 0 + end + object CbSelectUnlockedCells: TCheckBox + Left = 8 + Height = 19 + Top = 19 + Width = 300 + Align = alTop + BorderSpacing.Left = 8 + BorderSpacing.Right = 8 + Caption = 'select unlocked cells' + Checked = True + State = cbChecked + TabOrder = 1 + end + end +end diff --git a/applications/spready/sworksheetprotection.pas b/applications/spready/sworksheetprotection.pas new file mode 100644 index 000000000..5e7bc8412 --- /dev/null +++ b/applications/spready/sworksheetprotection.pas @@ -0,0 +1,87 @@ +unit sWorksheetProtection; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ButtonPanel, + StdCtrls, ExtCtrls, CheckLst, fpsTypes; + +type + + { TWorksheetProtectionForm } + + TWorksheetProtectionForm = class(TForm) + TopBevel: TBevel; + ButtonPanel: TButtonPanel; + CbProtect: TCheckBox; + CbSelectLockedCells: TCheckBox; + CbSelectUnlockedCells: TCheckBox; + LblProtectionItems: TLabel; + ItemsPanel: TPanel; + procedure CbProtectChange(Sender: TObject); + procedure FormCreate(Sender: TObject); + private + function GetProtected: Boolean; + function GetProtections: TsWorksheetProtections; + procedure SetProtected(AValue: Boolean); + procedure SetProtections(AValue: TsWorksheetProtections); + public + property IsProtected: Boolean read GetProtected write SetProtected; + property Protection: TsWorksheetProtections read GetProtections write SetProtections; + + end; + +var + WorksheetProtectionForm: TWorksheetProtectionForm; + +implementation + +{$R *.lfm} + +procedure TWorksheetProtectionForm.CbProtectChange(Sender: TObject); +var + unlocked: Boolean; +begin + unlocked := not IsProtected; + LblProtectionItems.Enabled := unlocked; + CbSelectLockedCells.Enabled := unlocked; + CbSelectUnlockedCells.Enabled := unlocked; +end; + +procedure TWorksheetProtectionForm.FormCreate(Sender: TObject); +begin + Constraints.MinHeight := ItemsPanel.Height + CbProtect.Height + + TopBevel.Height + ButtonPanel.Height; +end; + +function TWorksheetProtectionForm.GetProtected: Boolean; +begin + Result := CbProtect.Checked; +end; + +function TWorksheetProtectionForm.GetProtections: TsWorksheetProtections; +begin + Result := DEFAULT_SHEET_PROTECTION; + if CbSelectLockedCells.Checked then + Include(Result, spSelectLockedCells) else + Exclude(Result, spSelectLockedCells); + if CbSelectUnlockedCells.Checked then + Include(Result, spSelectUnlockedCells) else + Exclude(Result, spSelectUnlockedCells); +end; + +procedure TWorksheetProtectionForm.SetProtected(AValue: Boolean); +begin + CbProtect.Checked := AValue; +end; + +procedure TWorksheetProtectionForm.SetProtections(AValue: TsWorksheetProtections); +begin + CbSelectLockedCells.Checked := spSelectLockedCells in AValue; + CbSelectUnlockedCells.Checked := spSelectUnlockedCells in AValue; +end; + +end. +