密码保护 C# 中的 Excel 文件密码保护、文件、Excel

由网友(心事死在風裏)分享简介: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 progr...

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?

Excel文档保护密码忘记怎么办

Additional notes:

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

解决方案

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...

阅读全文

相关推荐

最新文章