2007年11月20日 星期二

匯出Excel~~~不使用tool產生html格式的xls

說明:
直接寫成html的格式
然後匯出成excel的格式
------------------------------------------------------------------------------

範例:

using System.IO;

Response.Clear();
Response.Charset = "big5";
Response.AddHeader("Content-Disposition",
"attachment;filename="+Server.UrlEncode(FileNameC)
);
Response.ContentType = "application/vnd.ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5");
Response.Write("<@html><@body>"); //拿掉@
Response.Write("<@meta http-equiv=Content-Type content=text/html; charset=big5>");//拿掉@
Response.Write("<@style type=text/css>");//拿掉@
Response.Write("td{mso-number-format:\"\\@\";}");
Response.Write(".formCaption1={back-color=#CECFCE;font-size=12px;height=24px;}");
Response.Write("");//拿掉@

System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter tw = new System.Web.UI.HtmlTextWriter(sw);
sw.WriteLine("");

sw.WriteLine("");
sw.WriteLine("
合格證資料轉出(批次-汽車)
列印日期:"+DateTime.Now.ToString("yyyy/MM/dd")+"
");
//title
sw.WriteLine(@"");

//detail
sw.WriteLine(@"");
sw.WriteLine("
...
...
");
Response.Write("
");
Response.Write(sw.ToString());
Response.Write("
");
Response.Write("");//拿掉@
Response.End();

沒有留言: