GridView导出Excel加上样式并且去除超链接
来源:互联网 发布:网络端口怎么设置 编辑:程序博客网 时间:2024/06/07 07:12
GridView导出Excel加上样式并且去除超链接
protected void BtnExcel_Click(object sender, EventArgs e){
Response.Clear();
//Response.AddHeader("content-disposition", "attachment;filename=考核结果.xls");
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("考核结果.xls",Encoding.UTF8).ToString());
Response.Charset = "gb2312";
Response.ContentType = "application/ms-excel";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
string strExcel = stringWrite.ToString();
//正则表达式,去除超链接,加个名称空间:System.Text.RegularExpressions;strExcel = Regex.Replace(strExcel, "<a (.*?)>", "", RegexOptions.Compiled);
strExcel = Regex.Replace(strExcel, "</a>", "");
//添加样式Response.Write(@"<style type='text/css'>
.width300{width:100px;}
</style>");
Response.Write(strExcel);
Response.End();
}
//如果没有下面方法会报错类型“GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标记内
public override void VerifyRenderingInServerForm(Control control)
{
}
0 0
- GridView导出Excel加上样式并且去除超链接
- 使用jxl导出Excel文件,并且设置Excel样式
- gridview导出到excel格式及标题样式
- Gridview导出Execl样式
- 一个高效的导出Excel方法,并且已解决导出会有样式文件夹的问题
- GridView导出Excel研究
- GridView导出Excel研究
- GridView导出Excel研究
- GridView导出Excel
- GridView格式化导出Excel
- GridView导出Excel研究
- GridView导出到Excel
- GridView导出Excel研究
- GridView导出Excel研究
- GridView导出Excel研究
- GridView导出Excel研究
- gridview导出Excel
- GridView导出Excel
- 对游戏活动的一点思考
- Java获取访问者的ip地址
- linux下有哪些音乐播放器
- 《UNIX环境高级编程》笔记--sigsetjmp和siglongjmp函数
- 使用vs2010和masm32搭建win32汇编语言编程编译环境
- GridView导出Excel加上样式并且去除超链接
- MATLAB计时方法
- 关于百度搜索
- Linux的学习经验
- NSJSONSerialization
- 16--2(指针)指来指去
- ubuntu更新命令
- 简单而直接的Python web 框架:web.py
- 11.java 时间和日期