views:

1873

answers:

3

Does anyone know the syntax for this? I've been looking everywhere and all I can find is C++ code for this. I'm trying to password protect an excel file programatically using the System.IO.Packaging namespace.

Any ideas?

Additional notes:

I'm NOT using the Excel interop--but instead the System.IO.Packaging namespace to encrypt and password protect the excel file.

A: 

It's not possible using System.IO.Packaging. You will have to use Microsoft.Office.Interop.Excel using the Worksheet.SaveAs method. This requires Excel being installed on your target system.

0xA3
A: 

You will have to use the SaveAs method on the Worksheet. It has a parameter to set a password. Here is an example in VB which can be converted to C#

http://www.codeproject.com/KB/office/Excel_Security.aspx

Although Excel (and COM automation in general) is way easier in VB than in C# (3.0).
0xA3
+1  A: 

If you want an Excel password all you need is something like this:

using Microsoft.Office.Interop.Excel

//create your spreadsheet here...

WorkbookObject.Password = password;
WorkbookObject.SaveAs("spreadsheet.xls")

This requires Excel to be installed.

That's nothing to do with System.IO.Packaging of course, so you might need to restate your question...

Colin Pickard