string path = System.IO.Path.Combine(HttpRuntime.AppDomainAppPath, @"Template代表建议留言模板.xls"); Workbook book = new Workbook(path); //book.Replace("Title", "测试活动233"); WorkbookDesigner wd = new WorkbookDesigner(book); wd.SetDataSource("HDTitle", data.List[0].activity_name);//替换值 System.Data.DataTable dt = (new ZW.DAL.T_Activity_Scene()).GetPageTable(search); dt.TableName = "tablename"; dt.Columns.Add("RowIndex", typeof(int)); dt.Columns.Add("name", typeof(string)); dt.Columns.Add("remark", typeof(string)); dt.Columns.Add("addtime", typeof(string)); dt.Columns.Add("HDTitle", typeof(string)); var row = dt.NewRow(); row["RowIndex"] = 1; row["name"] = "张三"; row["remark"] = "我的建议是233"; row["addtime"] = "2017-03-14"; row["HDTitle"] = "我的活动23333"; dt.Rows.Add(row); row = dt.NewRow(); row["RowIndex"] = 2; row["name"] = "李四"; row["remark"] = "我的建议是244"; row["addtime"] = "2017-03-14"; row["HDTitle"] = "我的活动43333"; dt.Rows.Add(row); wd.SetDataSource(dt); wd.Process(); System.IO.MemoryStream ms = wd.Workbook.SaveToStream(); byte[] bt = ms.ToArray(); //客户端保存的文件名 //以字符流的形式下载文件 string file = LzCommon.ToolsUtil.CreateTimeStamp() + "测试活动建议.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);