日期:2014-05-18  浏览次数:20515 次

导出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
------解决方案--------------------
一时想不起,做个记号