asp.net Excel匯出方法

ForTechnology發表於2011-12-01
 Response.ClearHeaders();
Response.Clear();
 Response.Expires = 0;
 Response.Buffer = true;
Response.Charset = "UTF-8";
 //把 attachment 改為 online 則線上開啟
 Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + FileName + "\"");                 
 Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
 string[] keyValue = sFileName.Split(".".ToCharArray());
 if (keyValue.Length >= 2)
 {
                        string type = (string)((keyValue[keyValue.Length - 1]).ToString());
                        Response.ContentType = GetResponseContentType(type);
  }
//獲取byte格式檔案從資料庫
byte[] bt = (byte[])DownLoadFile(Convert.ToDateTime(Server.UrlDecode(Request["SaveTime"])));
 if (bt.Length == 0)
 {
             byte[] tempArray = new byte[1];
              tempArray[0] = Convert.ToByte(' ');
             bt = tempArray;
 }
Response.OutputStream.Write(bt, 0, bt.Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
 Response.Flush();
 Response.End();


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25897606/viewspace-712515/,如需轉載,請註明出處,否則將追究法律責任。

相關文章