在以下按钮单击事件中实现:
private void btnmime_click(object sender, system.eventargs e)
{
binddata();
response.contenttype = "application/vnd.ms-excel";
response.addheader("content-disposition", "inline;filename="
+ httputility.urlencode("下载文件.xls",encoding.utf8 ) );
//如果输出为word,修改为以下代码
//response.contenttype = "application/ms-word"
//response.addheader("content-disposition", "inline;filename=test.doc")
stringbuilder sb=new stringbuilder();
system.io.stringwriter sw = new system.io.stringwriter(sb);
system.web.ui.htmltextwriter hw = new system.web.ui.htmltextwriter(sw);
sb.append("<html><body>");
dgshow.rendercontrol(hw);
sb.append("</body></html>");
response.write(sb.tostring());
response.end();
}
注:1.若datagrid中有按钮列,则在导出前应先将其隐藏.
2.若datagrid有分页,而又要打印所有数据的话就应先取消分页.
新闻热点
疑难解答
图片精选