asp.net gridview导入到Excel 导出后只有gridview以外的数据,刚好没有gridview中的数据 代码如下: 20
privatevoidExport(stringFileType,stringFileName){try{Response.Charset="UTF8";Response...
private void Export(string FileType, string FileName)
{
try
{
Response.Charset = "UTF8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8));
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
this.Gv_Data.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
catch (Exception err)
{
Response.Write("导出Excel出错!错误原因:" + err.Message);
}
} 展开
{
try
{
Response.Charset = "UTF8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8));
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
this.Gv_Data.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
catch (Exception err)
{
Response.Write("导出Excel出错!错误原因:" + err.Message);
}
} 展开
3个回答
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void btnExcel_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "学生成绩报表.xls");
}
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition",
"attachment;filename=" +
HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
gvwStudent.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
{
}
protected void btnExcel_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "学生成绩报表.xls");
}
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition",
"attachment;filename=" +
HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
gvwStudent.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询