其他分享
首页 > 其他分享> > 将DataGridview的内容保存到Excel

将DataGridview的内容保存到Excel

作者:互联网

protected void btnprint_Click(object sender, EventArgs e)
{
  Response.Charset = "GB2312";
  Response.ContentEncoding = System.Text.Encoding.UTF7;
  Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("考勤统计记录.xls", Encoding.UTF8).ToString());

  Response.ContentType = "application/ms-excel";
  this.EnableViewState = false;
  StringWriter tw = new StringWriter();
  HtmlTextWriter hw = new HtmlTextWriter(tw);
  gvSignInfoStatistic.RenderControl(hw);
  string print = string.Format("<br><br><center><font size=4 color='red'>制表人 : {0} &nbsp;&nbsp;上报日期 : {1}</font></centre>", lblReportUser.Text, lblReportTime.Text);
  hw.InnerWriter.Write(print);
  Response.Write(tw.ToString());
  Response.End();
}

 

标签:Text,Excel,保存,hw,nbsp,tw,print,DataGridview,Response
来源: https://www.cnblogs.com/BarlowNing/p/15874601.html