从ASP.NET C#中的gridview导出受密码保护的excel文件 [英] Export password protected excel file from gridview in ASP.NET C#

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

问题描述

亲爱的所有人,



我想将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文件添加密码保护。





谢谢

解决方案

为此目的使用库,如: NuGet Gallery | EPPlus 4.1.1 [ ^ ]

我们可以使用水晶报告(ASP.NET C#)导出受密码保护的Excel吗?





您必须使用 Interop [ ^ ]或任何第三方派对图书馆保护工作簿。

i会建议 GitHub - ClosedXML / ClosedXML: [ ^ ]以您想要的方式自定义Excel。



引用这些来将密码应用于该文件,然后您可以将其导出。

。使用Closedxml库创建受密码保护的Excel文件 [ ^ ]

表格保护·ClosedXML / ClosedXML Wiki·GitHub [ ^ ]


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

解决方案

Use a library for this purpose like : NuGet Gallery | EPPlus 4.1.1[^]


Can we export password protected excel using crystal report (ASP.NET C#)?


No


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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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