/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnExport_Click(object sender, EventArgs e) { try { DataSet ds = GetData(true); if (ds != null) { DataTable data = ds.Tables[1]; data.Columns.Add("sName", typeof(string)); foreach (DataRow dr in data.Rows) { dr["sName"] = Enum.GetName(typeof(viviapi.Model.SettledStatus), dr["status"]); } data.AcceptChanges(); data.TableName = "Rpt"; string path = Server.MapPath("~/common/template/xls/settle.xls"); var designer = new Aspose.Cells.WorkbookDesigner(); designer.Workbook = new Workbook(path); //数据源 designer.SetDataSource(data); designer.Process(); designer.Workbook.Save(this.Response , DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls" , ContentDisposition.Attachment , designer.Workbook.SaveOptions); } } catch (Exception ex) { AlertAndRedirect(ex.Message); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnExport_Click(object sender, EventArgs e) { try { if (rbl_export_mode.SelectedValue == "2") { #region txt string ids = Request.Form["ischecked"]; if (string.IsNullOrEmpty(ids)) { return; } var builder = new StringBuilder(); DataTable table = GetData(true).Tables[0]; foreach (DataRow row in table.Rows) { builder.AppendFormat("{0};{1};{2};{3};--;--;{4:f2}", row["UserName"], row["PayeeName"], row["Account"], row["PayeeBank"], row["RealAmt"]); //builder.Append(string.Concat(new object[] { row["UserName"].ToString(), ";", row["PayeeName"], ";", row["Account"], ";", row["PayeeBank"], ";--;--;", row["RealAmt"] })); builder.Append("\r\n"); } string str3 = builder.ToString(); StringWriter writer = new StringWriter(); writer.Write(str3); writer.WriteLine(); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = false; HttpContext.Current.Response.Charset = "GB2312"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt"); HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding("GB2312"); HttpContext.Current.Response.Write(writer); HttpContext.Current.Response.End(); #endregion } else { DataSet ds = GetData(true); if (ds != null) { DataTable data = ds.Tables[1]; data.Columns.Add("sName", typeof(string)); foreach (DataRow dr in data.Rows) { dr["sName"] = Enum.GetName(typeof(viviapi.Model.SettledStatus), dr["status"]); } data.AcceptChanges(); data.TableName = "Rpt"; string path = Server.MapPath("~/common/template/xls/settle.xls"); var designer = new Aspose.Cells.WorkbookDesigner(); designer.Workbook = new Workbook(path); //数据源 designer.SetDataSource(data); designer.Process(); designer.Workbook.Save(this.Response , DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls" , ContentDisposition.Attachment , designer.Workbook.SaveOptions); } } } catch (Exception ex) { AlertAndRedirect(ex.Message); } }