protected void btnLoadOut_Click(object sender, EventArgs e) { ChangeTrackingList <EntitySearcher> changeTrackingList = ViewState["sql"] as ChangeTrackingList <EntitySearcher>; List <FineOffice.Modules.CRM_Trader> list = traderBll.GetList(changeTrackingList); FineOffice.Web.WebExcelHelper excelHelper = new FineOffice.Web.WebExcelHelper(); FineOffice.Common.Excel.ExcelHelper toExcel = new FineOffice.Common.Excel.ExcelHelper(); string serverPath = Server.MapPath("~/Config/Template/CRM_Trader.xml"); List <ExcelHeader> headerList = toExcel.GetHeaderList(serverPath); toExcel.ApplicationName = excelHelper.ApplicationName; toExcel.Author = excelHelper.Author; toExcel.Comments = excelHelper.Comments; System.IO.MemoryStream ms = toExcel.Export <FineOffice.Modules.CRM_Trader>(list, traderGrid.Title, headerList); byte[] output = ms.ToArray(); FineOffice.Web.FileTypeHelper typeHelper = new FineOffice.Web.FileTypeHelper(); Response.AddHeader("Content-Disposition", "attachment; filename=" + typeHelper.ToHexString(string.Format("{0}{1:yyyyMMdd}", traderGrid.Title, DateTime.Now) + ".xls")); Response.AddHeader("Content-Length", output.Length.ToString()); Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); Response.OutputStream.Write(output, 0, output.Length); Response.Flush(); Response.End(); }
protected void btnDownAttachment_Click(object sender, EventArgs e) { int id = int.Parse(attachmentGrid.DataKeys[attachmentGrid.SelectedRowIndex][0].ToString()); FineOffice.Modules.OA_Attachment model = attBll.GetModel(d => d.ID == id); byte[] attachmentData = SharpZipLib.DeCompress(model.AttachmentData); FineOffice.Web.FileTypeHelper typeHelper = new FineOffice.Web.FileTypeHelper(); Response.Clear(); Response.Buffer = true; Response.Charset = "utf-8"; Response.AddHeader("Content-Disposition", "attachment; filename=" + typeHelper.ToHexString(model.FileName + "." + model.XType)); Response.AddHeader("Content-Length", attachmentData.Length.ToString()); Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); Response.OutputStream.Write(attachmentData, 0, attachmentData.Length); Response.Flush(); }
protected void btnTemplates_Click(object sender, EventArgs e) { FineOffice.Web.WebExcelHelper excelHelper = new FineOffice.Web.WebExcelHelper(); FineOffice.Common.Excel.ExcelHelper toExcel = new FineOffice.Common.Excel.ExcelHelper(); string serverPath = Server.MapPath("~/Config/Template/CNS_CensusMember.xml"); List <ExcelHeader> headerList = toExcel.GetHeaderList(serverPath); toExcel.ApplicationName = excelHelper.ApplicationName; toExcel.Author = excelHelper.Author; toExcel.Comments = excelHelper.Comments; System.IO.MemoryStream ms = toExcel.Export <FineOffice.Modules.CNS_CensusMember>(new List <FineOffice.Modules.CNS_CensusMember>(), memberGird.Title, headerList); byte[] output = ms.ToArray(); FineOffice.Web.FileTypeHelper typeHelper = new FineOffice.Web.FileTypeHelper(); Response.AddHeader("Content-Disposition", "attachment; filename=" + typeHelper.ToHexString(memberGird.Title + ".xls")); Response.AddHeader("Content-Length", output.Length.ToString()); Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); //设置输出流的字符集 Response.OutputStream.Write(output, 0, output.Length); //输出 Response.Flush(); Response.End(); }