Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated instructions and images to Excel 2010

...

Code Block
c#
c#
titleWorkbook Encryption
//--- To encrypt a workbook, use the Workbook.EncryptPassword property:
ExcelApplication xlw = new ExcelApplication();
Workbook wb = xlw.Create();
wb.EncryptPassword = "myPassword";
xlw.Save(wb, outPath);

How to Activate Worksheet Protection with ExcelWriter

...

Create a workbook in Microsoft Excel, open click the Tools menuReview tab, and select Protection -> Protect sheet. Next, select the password you want to protect with and the properties you would like to set and click OK. Then, open the spreadsheet with ExcelWriter script, using either ExcelTemplate or ExcelApplication.Open. ExcelWriter will preserve all existing spreadsheet settings, including worksheet protection.

Image RemovedImage Added

Protect in ExcelWriter Code

...

  1. Select a cell or cells to unlock.
  2. From the Format menu select CellsRight click and hit Format Cell(s)...
  3. Select the Protection tab.
  4. Uncheck Locked.

Image RemovedImage Added

With ExcelWriter, you can unlock cells by setting Style.CellLocked to false and applying the style to an individual cell. The following example protects all cells except for A1 and B1:

...