首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

导出Excel后所有内容都在一个单元格里!解决方案

2012-02-05 
导出Excel后所有内容都在一个单元格里!直接贴代码了!protected void Button3_Click(object sender, EventA

导出Excel后所有内容都在一个单元格里!
直接贴代码了! 

  protected void Button3_Click(object sender, EventArgs e)
  {
  Response.Clear();
  Response.Buffer = true;
  Response.Charset = "utf-8";
  Response.AppendHeader("Content-Disposition", "attachment;filename=statzy.xls");
  Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");//设置输出流为简体中文
  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);
  this.DIV1.RenderControl(oHtmlTextWriter);//将服务器控件的内容输出
  Response.Write(oStringWriter.ToString());
  Response.End();
 }
我用的是把table导成Excel。


[解决办法]
function excelPrint(objStr){
var tempStr = document.getElementById('table1').outerHTML;
var newWin = window.open();
newWin.document.write(tempStr);
newWin.document.close();
newWin.document.execCommand('saveas',true,objStr+'.xls');
newWin.window.close();
}
DIV1是否为div
http://www.cnblogs.com/meiproject/articles/1059062.html
[解决办法]
一时想不起,做个记号

热点排行