密码保护C#中的Excel文件 [英] Password Protecting an Excel file in C#

查看:248
本文介绍了密码保护C#中的Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道这个的语法?我一直在寻找无处不在,我可以找到的是C ++代码。我正在使用System.IO.Packaging命名空间来编程地密码保护excel文件。



任何想法?



附加说明:



我没有使用Excel interop,而是使用System.IO.Packaging命名空间来加密和密码保护excel文件。

解决方案

如果你想要一个Excel密码,你需要的是这样的:

 使用Microsoft.Office.Interop.Excel 

//在此创建您的电子表格

WorkbookObject.Password =密码;
WorkbookObject.SaveAs(spreadsheet.xls)

这需要安装Excel。



System.IO.Packaging 无关,所以您可能需要重申您的问题。 ..


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.

解决方案

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

这篇关于密码保护C#中的Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆