asp.net导出数据生成真正的excel文件
asp.net导出数据生成excel文件,如果修改了生成的excel文件它会生成其它几个文件,例如怎样防止啊...
asp.net导出数据生成excel文件,如果修改了生成的excel文件它会生成其它几个文件,例如怎样防止啊
展开
2个回答
推荐于2016-08-09
展开全部
我一般都是用gridview导出数据,你看看代码吧 对你有没有帮助, ----------------------按钮事件-------------------protected void Button2_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "sssss.xls");
} private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
// turn off paging
GridView1.AllowPaging = false;
this.GridView1.DataBind(); GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End(); // turn the paging on again
GridView1.AllowPaging = true;
this.GridView1.DataBind(); } 下面这句不加的话回出错误 public override void VerifyRenderingInServerForm(Control control)
{ }页面:EnableEventValidation = "false"
{
Export("application/ms-excel", "sssss.xls");
} private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
// turn off paging
GridView1.AllowPaging = false;
this.GridView1.DataBind(); GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End(); // turn the paging on again
GridView1.AllowPaging = true;
this.GridView1.DataBind(); } 下面这句不加的话回出错误 public override void VerifyRenderingInServerForm(Control control)
{ }页面:EnableEventValidation = "false"
2013-06-28
展开全部
楼主是想将数据库中的数据字段,读出来,存到excel文档?还是想直接读出就是excel文档?对于前者,我可以解决;后者我只是有点设计思想,目前还没实现
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询