Aspose.Cell C# 匯出資料
阿新 • • 發佈:2022-05-24
DataTable dt = dal.ExecuteDataTable(cmd, null); dt.TableName = "tb"; string path = System.IO.Path.Combine(HttpRuntime.AppDomainAppPath, @"Template\結果匯出模版.xls"); Workbook book = new Workbook(path); WorkbookDesigner wd = new WorkbookDesigner(book); //string title = string.Format("{0} 至 {1} 活躍度", sd.ToString("yyyy-MM-dd"), ed.ToString("yyyy-MM-dd"));//wd.SetDataSource("Title", title);//替換值 wd.SetDataSource(dt); wd.Process(); System.IO.MemoryStream ms = wd.Workbook.SaveToStream(); byte[] bt = ms.ToArray(); //客戶端儲存的檔名 //以字元流的形式下載檔案 string file = string.Format("{0}.xls", "結果匯出"); System.Web.HttpContext.Current.Response.ContentType= "application/vnd.ms-excel"; System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + file); System.Web.HttpContext.Current.Response.OutputStream.Write(bt, 0, bt.Length);