JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » .Net Framework » .NET Web Tech: Webform ,.net MVC  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 將資料庫的資料撈出來轉成execl
natt91056





發文: 2
積分: 0
於 2011-12-20 11:39 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
麻煩各位大大能否告知
我想詢問一下,我本身已經在Member.asp.cs檔內已經寫好
public static void DownloadExcel(DataTable dt)
{
// 產生 Excel 資料流。
MemoryStream ms = RenderDataTableToExcel(dt) as MemoryStream;
// 設定強制下載標頭。
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=Download.xls"));
// 輸出檔案。
HttpContext.Current.Response.BinaryWrite(ms.ToArray());
}
public static Stream RenderDataTableToExcel(DataTable SourceTable)
{
HSSFWorkbook workbook = new HSSFWorkbook();
MemoryStream ms = new MemoryStream();
HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet();
HSSFRow headerRow = (HSSFRow)sheet.CreateRow(0);
// handling header.
foreach (DataColumn column in SourceTable.Columns)
headerRow.CreateCell(column.Ordinal).SetCellValue(column.ColumnName);
// handling value.
int rowIndex = 1;
foreach (DataRow row in SourceTable.Rows)
{
HSSFRow dataRow = (HSSFRow)sheet.CreateRow(rowIndex);
foreach (DataColumn column in SourceTable.Columns)
{
dataRow.CreateCell(column.Ordinal).SetCellValue(row[column].ToString());
}
rowIndex++;
}
workbook.Write(ms);
ms.Flush();
ms.Position = 0;
sheet = null;
headerRow = null;
workbook = null;
return ms;
}
可是要怎麼在Member.asp檔寫上呼叫Member.asp.cs呢???麻煩各位大大


reply to postreply to post
» JWorld@TW »  .Net Framework » .NET Web Tech: Webform ,.net MVC

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8