Save Workbook with password

Hi,


I’m trying to set a password for opening a workbook.
I have found only this way by looking at your documentation:

Workbook MyWorkBook = new Workbook();
MyWorkBook.Worksheets[0].Protect(ProtectionType.All, “MyPassword”, null);
MyWorkBook.Save(@“C:\Tmp\MyWorkbook.xls”);

But the result isn’t what I expected.
I don’t want the document to be openable without a password.
How can I do it?

Thanks,
Devid.

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please use the following code to password protect your file. The output file will not open unless you provide a password.

C#


Workbook workbook = new Workbook();


workbook.Settings.Password = “123”;


workbook.Save(“output.xlsx”);

It works.


Thanks a lot for your help!

Regards,
Devid

Hi,

Thanks for your posting and using Aspose.Cells.

We are glad to know your issue is resolved now. Please feel free to contact us if you encounter any other issue, we will be happy to help you more.