zoukankan      html  css  js  c++  java
  • 导出

    JS

    function ChoiceExport() {
    if (Ext.getCmp('Exportthewaya').getValue() == true && Ext.getCmp('Checkbox1').getValue() == true) {
    ExportType.setValue('ExportAll');
    ExportGrid.submitData(false);
    }
    else if (Ext.getCmp('Exportthewaya').getValue() == true) {
    ExportType.setValue('ExportAllOne');
    ExportGrid.submitData(false);
    }
    else if (Ext.getCmp('Checkbox1').getValue() == true) {
    ExportType.setValue('ExportAllTwo');
    ExportGrid.submitData(false);
    }
    else {

    }
    }

    --------------------------------------------------------------------------------

    EXT.NET 前台代码

    <ext:Button ID="ExportBut" runat="server" Icon="DiskDownload" Text="ConditionalExport">
    <Listeners>
    <Click Handler="ExportType.setValue('ConditionalExport');#{ExportGrid}.submitData(false);" />
    </Listeners>
    </ext:Button>
    <ext:Button ID="Button3" runat="server" Icon="DiskDownload" Text="Export ALL">
    <Listeners>
    <Click Handler="ExportWindowShow()" />
    </Listeners>
    </ext:Button>

    ----------------------------------------------------------------

    <ext:GridPanel runat="server"
    ID="ExportGrid"
    Title="Export Data"
    Header="false"
    Hidden="true"
    StripeRows="true"
    Icon="Application"
    Region="Center"
    Frame="true">
    <Store>
    <ext:Store runat="server" ID="ExportStore" OnSubmitData="Export_Submit">
    <DirectEventConfig IsUpload="true" />
    <Reader>
    <ext:JsonReader>
    <Fields>
    <ext:RecordField Name="Id"></ext:RecordField>
    </Fields>
    </ext:JsonReader>
    </Reader>
    </ext:Store>
    </Store>
    <ColumnModel>
    <Columns>
    <ext:Column Header="Id" DataIndex="Id"></ext:Column>
    </Columns>
    </ColumnModel>
    </ext:GridPanel>

    ---------------------------------------------------------------------------------

    后台代码

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!X.IsAjaxRequest)
    {
    Data_Bind();
    }
    }

    #region 导出
    /// <summary>
    /// 导出
    /// </summary>
    private void Data_Bind()
    {
    ExportStore.DataSource = new object[] { "Export" };
    ExportStore.DataBind();
    }

    /// <summary>
    /// Export
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Export_Submit(object sender, StoreSubmitDataEventArgs e)
    {
    List<IDataParameter> pList3 = new List<IDataParameter>();
    string TempPathAll = Server.MapPath(string.Format("~/Temp/ExchangeRate/{0:yyyyMMddHHmmssfff}/", DateTime.Now));
    if (!Directory.Exists(TempPathAll))
    Directory.CreateDirectory(TempPathAll);
    string FileNameAllA = String.Format("ExchangeRateAll(A)_{0:yyyyMMddHHmmssfff}.csv", DateTime.Now);
    string FileNameAllB = String.Format("ExchangeRateAll(B)_{0:yyyyMMddHHmmssfff}.csv", DateTime.Now);
    //string FilePathAll = TempPathAll + FileNameAll;
    string zipFileName = string.Format("ExchangeRateAll_{0:yyyyMMddHHmmssfff}.zip", DateTime.Now);
    string zipFolderPath = string.Format("{0}{1}", TempPathAll, zipFileName);
    DataSet ds3 = DataProvider.Instance().ExecProcedure("R_Parities_Config_CurrencyExchangeRateExportAll", pList3);

    var resultA = from r in ds3.Tables[0].AsEnumerable()
    orderby DateTime.Parse(r["EffectiveDate"].ToString()) descending
    select r;
    DataTable TableA = resultA.CopyToDataTable();

    switch (ExportType.Text)
    {
    case "ConditionalExport":
    List<IDataParameter> pList = new List<IDataParameter>();
    if (FromCodeName.SelectedItems.Count > 0)
    {
    string FromCodeTwo = "";
    foreach (SelectedListItem item in FromCodeName.SelectedItems)
    {
    FromCodeTwo += String.Format(",{0}", item.Value);
    }
    pList.Add(DataProvider.Instance().NewParameter("@FromCode", DbType.String, 400, FromCodeTwo.TrimStart(',').ToString()));
    }
    else
    {
    string FromCodeTwoNew = "CAD,GBP";
    pList.Add(DataProvider.Instance().NewParameter("@FromCode", DbType.String, 400, FromCodeTwoNew));
    }
    string ToCodeTwo = "USD";
    if (ToCodeName.SelectedItem.Text != "")
    {
    ToCodeTwo = ToCodeName.SelectedItem.Text.Trim().ToString();
    }
    pList.Add(DataProvider.Instance().NewParameter("@ToCode", DbType.String, 400, ToCodeTwo));
    pList.Add(DataProvider.Instance().NewParameter("@EffectiveDate", DbType.String, 400, EffectiveDateName.Text.Trim().ToString()));
    pList.Add(DataProvider.Instance().NewParameter("@ChangeDate", DbType.String, 400, ChangeDateName.Text.Trim().ToString()));
    DataSet ds = DataProvider.Instance().ExecProcedure("R_Parities_Config_CurrencyExchangeRateExport", pList);
    string fileName = String.Format("ExchangeRate_{0:yyyyMMddHHmmssfff}.xls", DateTime.Now);
    ExcelExport5(ds, fileName, new string[] { "ExchangeRate", "DETAILS" });
    break;

    case "ExportAllOne":
    //List<IDataParameter> pList1 = new List<IDataParameter>();
    //DataSet ds1 = DataProvider.Instance().ExecProcedure("R_Parities_Config_CurrencyExchangeRateExportAll", pList1);
    //string fileName1 = String.Format("ExchangeRateAll(A)_{0:yyyyMMddHHmmssfff}.xls", DateTime.Now);
    //DataTable dt1 = ds1.Tables[0];
    //ExcelExport3(dt1, fileName1, "ExchangeRateAll(A)");
    Helper.ExportDataTableToCSV(TableA, FileNameAllA, TempPathAll);
    string err;
    if (!Ecom.Helper.Zip.ZipFile(TempPathAll, zipFolderPath, out err))
    LogWrite("ExchangeRate", string.Format("Export ExchangeRate all(A) error, {0}", err));
    else
    LogWrite("ExchangeRate", string.Format("Export ExchangeRate all(A), {0}", zipFolderPath));

    Response.Clear();
    Response.Buffer = true;
    Response.Charset = "GB2312";
    Response.AppendHeader("Content-Disposition", "attachment;filename=" + zipFileName);
    Response.ContentEncoding = Encoding.GetEncoding("GB2312");//设置输出流为简体中文
    Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
    EnableViewState = false;
    Response.BinaryWrite(File.ReadAllBytes(zipFolderPath));
    Response.End();
    break;

    case "ExportAllTwo":
    //List<IDataParameter> pList2 = new List<IDataParameter>();
    //DataSet ds2 = DataProvider.Instance().ExecProcedure("R_Parities_Config_CurrencyExchangeRateExportAll", pList2);
    //string fileName2 = String.Format("ExchangeRateAll(B)_{0:yyyyMMddHHmmssfff}.xls", DateTime.Now);
    //DataTable dt2 = ds2.Tables[1];
    //ExcelExport3(dt2, fileName2, "ExchangeRateAll(B)");
    Helper.ExportDataTableToCSV(ds3.Tables[1], FileNameAllB, TempPathAll);
    string err1;
    if (!Ecom.Helper.Zip.ZipFile(TempPathAll, zipFolderPath, out err1))
    LogWrite("ExchangeRate", string.Format("Export ExchangeRate all(B) error, {0}", err1));
    else
    LogWrite("ExchangeRate", string.Format("Export ExchangeRate all(B), {0}", zipFolderPath));

    Response.Clear();
    Response.Buffer = true;
    Response.Charset = "GB2312";
    Response.AppendHeader("Content-Disposition", "attachment;filename=" + zipFileName);
    Response.ContentEncoding = Encoding.GetEncoding("GB2312");//设置输出流为简体中文
    Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
    EnableViewState = false;
    Response.BinaryWrite(File.ReadAllBytes(zipFolderPath));
    Response.End();
    break;

    case "ExportAll":
    //List<IDataParameter> pList3 = new List<IDataParameter>();
    //string TempPathAll = Server.MapPath(string.Format("~/Temp/ExchangeRate/{0:yyyyMMddHHmmssfff}/", DateTime.Now));
    //if (!Directory.Exists(TempPathAll))
    // Directory.CreateDirectory(TempPathAll);
    //string FileNameAllA = String.Format("ExchangeRateAll(A)_{0:yyyyMMddHHmmssfff}.csv", DateTime.Now);
    //string FileNameAllB = String.Format("ExchangeRateAll(B)_{0:yyyyMMddHHmmssfff}.csv", DateTime.Now);
    ////string FilePathAll = TempPathAll + FileNameAll;
    //string zipFileName = string.Format("ExchangeRateAll_{0:yyyyMMddHHmmssfff}.zip", DateTime.Now);
    //string zipFolderPath = string.Format("{0}{1}", TempPathAll, zipFileName);

    Helper.ExportDataTableToCSV(TableA, FileNameAllA, TempPathAll);
    Helper.ExportDataTableToCSV(ds3.Tables[1], FileNameAllB, TempPathAll);
    string err2;
    if (!Ecom.Helper.Zip.ZipFile(TempPathAll, zipFolderPath, out err2))
    LogWrite("ExchangeRate", string.Format("Export ExchangeRate all error, {0}", err2));
    else
    LogWrite("ExchangeRate", string.Format("Export ExchangeRate all, {0}", zipFolderPath));

    Response.Clear();
    Response.Buffer = true;
    Response.Charset = "GB2312";
    Response.AppendHeader("Content-Disposition", "attachment;filename=" + zipFileName);
    Response.ContentEncoding = Encoding.GetEncoding("GB2312");//设置输出流为简体中文
    Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
    EnableViewState = false;
    Response.BinaryWrite(File.ReadAllBytes(zipFolderPath));
    Response.End();
    break;
    }
    }
    #endregion

  • 相关阅读:
    推荐电影 迪士尼经典动画片大全 1937-2008
    推荐电影 奥黛丽赫本的十大经典电影 1953-1989
    生活娱乐 ATM机键盘余温泄露密码
    生活娱乐 Wifi机器人的制作流程
    生活娱乐 WIFI机器人(某机器发烧友自己动手做一台)
    电脑技巧 ADSL如何远程盗号
    生活娱乐 VERYCD的T恤设计大赛
    系统重装 如何在固态硬盘上重装系统
    Visual Studio VS如何统计代码行数
    解决启动nginx时报80端口被占用的问题
  • 原文地址:https://www.cnblogs.com/dwuge/p/5292727.html
Copyright © 2011-2022 走看看