Aspose.Cell C# 导出数据
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);