首页 > 开发 > 综合 > 正文

DataGrid数据导入Excel

2024-07-21 02:25:04
字体:
来源:转载
供稿:网友
,欢迎访问网页设计爱好者web开发。if(datagrid1.items.count==0)
    {
     response.write("<script>alert('对不起,你没有查询到任何记录,不能导出数据')</script>");
    }
    else
    {     

     response.clear();
     response.buffer= true;
     response.charset="gb2312";
     response.appendheader("content-disposition","attachment;filename=filename.xls");
     response.contentencoding=system.text.encoding.getencoding("gb2312");
     //设置输出流为简体中文
     response.contenttype = "application/ms-excel";
     //设置输出文件类型为excel文件。
     this.enableviewstate = false;
     system.globalization.cultureinfo mycitrad = new system.globalization.cultureinfo("zh-cn",true);
     system.io.stringwriter ostringwriter = new system.io.stringwriter(mycitrad);
     system.web.ui.htmltextwriter ohtmltextwriter = new system.web.ui.htmltextwriter(ostringwriter);
     datagrid1.rendercontrol(ohtmltextwriter);
     response.write(ostringwriter.tostring());
     response.end();

}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表