如何使用Datalist导出受密码保护的excel文件..以下是我的代码... [英] How to export password protected excel file by using Datalist.. Following is my code...
问题描述
string attachment = attachment; filename = detail.xls;
Response.ClearContent();
Response.AddHeader( password , 1234 );
Response.AddHeader( content-disposition ,附件);
Response.ContentType = application / ms-excel ;
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();
DataList1.Parent.Controls.Add( frm);
frm.Attributes [ runat ] =服务器 ;
frm.Controls.Add(DataList1);
frm.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
已添加 pre
标签。
[/编辑]
参考 - Re:在asp.net c#中使用受密码保护的表格导出Excel [ ^ ]。
Quote:生成excel文件的方式并不是excel文件。它是一个html文件,在excel中显示,没有任何错误,因为它满足了大多数要求。但是如果你想生成受密码保护的excel文件,那么你必须生成真正的excel文件。
这些链接可能对你有用:
在Excel工作簿上实施密码安全性使用Visual Studio .NET [ ^ ]
http://social.msdn.microsoft.com/Forums/en-US/os_specifications/thread/7021768e-4562-43dd-9d5e-89c10970bf33/ [ ^ ]
或只是搜索互联网任何第三方付费/免费c omponent。
试试这个 -
Password-Protected-Secured-PDF-in-ASPNet [ ^ ]
string attachment = "attachment; filename=detail.xls;
Response.ClearContent();
Response.AddHeader("password", "1234");
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();
DataList1.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(DataList1);
frm.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
[Edit member="Tadit"]
Added pre
tags.
[/Edit]
Refer - Re: Export Excel with password protected sheet in asp.net c#[^].
Quote:The way you are generating excel file is not actully a excel file. it's a html file which is displayed in excel and nothing wrong in it, as it fullfil most of the requriements. But if you want to generate the password protected excel file, then you have to generate the real excel file.
These links might be usefull to you:
Implementing Password Security on Excel Workbooks Using Visual Studio .NET[^]
http://social.msdn.microsoft.com/Forums/en-US/os_specifications/thread/7021768e-4562-43dd-9d5e-89c10970bf33/[^]
or just search internet for any third party paid/free component.
Hi,
Try this-
Password-Protected-Secured-PDF-in-ASPNet[^]
这篇关于如何使用Datalist导出受密码保护的excel文件..以下是我的代码...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!