问题描述
亲爱的所有人,
我想将GridView / Repeater导出到受密码保护的Excel文件。
目前我在没有密码的情况下进行出口。
我尝试了什么:
Response.ClearContent();
Response.AddHeader( content-disposition, attachment; filename = CandidateList.xls);
Response.AddHeader( Content-Type, application / vnd.ms-excel);
Response.ContentEncoding = Encoding.Unicode;
Response.BinaryWrite(Encoding.Unicode.GetPreamble());
使用(StringWriter sw = new StringWriter())
{
使用(HtmlTextWriter htw = new HtmlTextWriter(sw))
{
GridView grid = new GridView();
grid.DataSource = exportcandidateList;
grid.DataBind();
string headerTable = @ < Table> ;< tr>< td colspan ='12'>< center> 候选人 - + ddlCenter.SelectedItem.ToString()。ToUpper()+ < / center>< / td>< / tr>< / Table>;
Response.Write(headerTable);
grid.RenderControl(htw);
Response.Write(sw.ToString());
}
}
Response.End();
我们可以使用水晶报告(ASP.NET C#)导出受密码保护的Excel吗?
任何人都可以帮助我,如何在导出时为excel文件添加密码保护。
谢谢
您必须使用 []或任何第三方派对图书馆保护工作簿。
i会建议 []以您想要的方式自定义Excel。
引用这些来将密码应用于该文件,然后您可以将其导出。
[]
[]
Dear All,
I want to export GridView/Repeater to password protected excel file.
Currently i'm doing export without password.
What I have tried:
Response.ClearContent(); Response.AddHeader("content-disposition", "attachment;filename=CandidateList.xls"); Response.AddHeader("Content-Type", "application/vnd.ms-excel"); Response.ContentEncoding = Encoding.Unicode; Response.BinaryWrite(Encoding.Unicode.GetPreamble()); using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { GridView grid = new GridView(); grid.DataSource = exportcandidateList; grid.DataBind(); string headerTable = @"<Table><tr><td colspan='12'><center>Candidates - " + ddlCenter.SelectedItem.ToString().ToUpper() + " </center></td></tr></Table>"; Response.Write(headerTable); grid.RenderControl(htw); Response.Write(sw.ToString()); } } Response.End();
Can we export password protected excel using crystal report (ASP.NET C#)?
Can anyone please help me, how can i add password protect to the excel file while exporting.
Thanks
You will have to use Interop [^] or any third party library to protect the workbook.
i would suggest GitHub - ClosedXML/ClosedXML: [^] to customise the excel the way you wanted.
refer these to apply password to the file and then you can export it.
. Create password protected excel file using Closedxml library [^]
Sheet Protection · ClosedXML/ClosedXML Wiki · GitHub[^]
这篇关于从ASP.NET C#中的gridview导出受密码保护的excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!