natt91056
   
發文: 2
積分: 0
|
於 2011-12-20 11:39
     
麻煩各位大大能否告知 我想詢問一下,我本身已經在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呢???麻煩各位大大
 
|