You've already forked lazarus-ccr
fpspreadsheet: Add demo_protection
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6549 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
69
components/fpspreadsheet/examples/other/demo_protection.lpi
Normal file
69
components/fpspreadsheet/examples/other/demo_protection.lpi
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<General>
|
||||||
|
<Flags>
|
||||||
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
<MainUnitHasScaledStatement Value="False"/>
|
||||||
|
</Flags>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
<MainUnit Value="0"/>
|
||||||
|
<Title Value="demo_protection"/>
|
||||||
|
<UseAppBundle Value="False"/>
|
||||||
|
<ResourceType Value="res"/>
|
||||||
|
</General>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="Default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<FormatVersion Value="2"/>
|
||||||
|
<Modes Count="0"/>
|
||||||
|
</RunParams>
|
||||||
|
<RequiredPackages Count="1">
|
||||||
|
<Item1>
|
||||||
|
<PackageName Value="laz_fpspreadsheet"/>
|
||||||
|
</Item1>
|
||||||
|
</RequiredPackages>
|
||||||
|
<Units Count="1">
|
||||||
|
<Unit0>
|
||||||
|
<Filename Value="demo_protection.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit0>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="demo_protection"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||||
|
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
</SearchPaths>
|
||||||
|
<Linking>
|
||||||
|
<Debugging>
|
||||||
|
<UseExternalDbgSyms Value="True"/>
|
||||||
|
</Debugging>
|
||||||
|
</Linking>
|
||||||
|
</CompilerOptions>
|
||||||
|
<Debugging>
|
||||||
|
<Exceptions Count="3">
|
||||||
|
<Item1>
|
||||||
|
<Name Value="EAbort"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<Name Value="ECodetoolError"/>
|
||||||
|
</Item2>
|
||||||
|
<Item3>
|
||||||
|
<Name Value="EFOpenError"/>
|
||||||
|
</Item3>
|
||||||
|
</Exceptions>
|
||||||
|
</Debugging>
|
||||||
|
</CONFIG>
|
53
components/fpspreadsheet/examples/other/demo_protection.pas
Normal file
53
components/fpspreadsheet/examples/other/demo_protection.pas
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
program demo_protection;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils,
|
||||||
|
fpstypes, fpspreadsheet, fpsallformats, fpsutils, fpscrypto;
|
||||||
|
|
||||||
|
const
|
||||||
|
PASSWORD = 'lazarus';
|
||||||
|
|
||||||
|
var
|
||||||
|
book: TsWorkbook;
|
||||||
|
sheet: TsWorksheet;
|
||||||
|
cell: PCell;
|
||||||
|
c: TsCryptoInfo;
|
||||||
|
begin
|
||||||
|
book := TsWorkbook.Create;
|
||||||
|
try
|
||||||
|
sheet := book.AddWorksheet('Sheet1');
|
||||||
|
|
||||||
|
// Add an unprotected cell
|
||||||
|
cell := sheet.WriteText(0, 0, 'Unprotected cell');
|
||||||
|
sheet.WriteCellProtection(cell, []);
|
||||||
|
|
||||||
|
// Add a protected cell
|
||||||
|
sheet.WriteText(1, 0, 'Protected cell');
|
||||||
|
|
||||||
|
// Activate worksheet protection such that a password is required to
|
||||||
|
// change the protection state
|
||||||
|
InitCryptoInfo(c);
|
||||||
|
c.Algorithm := caExcel;
|
||||||
|
c.PasswordHash := Format('%.4x', [ExcelPasswordHash(PASSWORD)]);
|
||||||
|
sheet.CryptoInfo := c;
|
||||||
|
sheet.Protection := [spDeleteRows, spDeleteColumns, spInsertRows, spInsertColumns];
|
||||||
|
sheet.Protect(true);
|
||||||
|
|
||||||
|
book.WriteToFile('protected.xls', sfExcel8, true);
|
||||||
|
book.WriteToFile('protected.xlsx', sfOOXML, true);
|
||||||
|
// Note ODS does not write the excel password correctly, yet. --> protection cannot be removed.
|
||||||
|
book.WriteToFile('protected.ods', sfOpenDocument, true);
|
||||||
|
|
||||||
|
finally
|
||||||
|
book.Free;
|
||||||
|
end;
|
||||||
|
|
||||||
|
WriteLn('Open the files "protected.*" in your spreadsheet application.');
|
||||||
|
WriteLn('Only cell A1 can be modifed.');
|
||||||
|
WriteLn('Press [ENTER] to quit...');
|
||||||
|
ReadLn;
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
Reference in New Issue
Block a user