B/S excel로 데이터 내보내기

축적편2:
지난번 winform에서 쓴 데이터의 도출이 좀 번거로웠던 것 같습니다. 이번에는 선배의 방법을 통합했습니다. 비교적 간단하지만 결함: 표 이름이 고정된
다음은 어떻게 실현되었는지 살펴보자.
    /// <summary>
    ///  
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// *** 12.12
    protected void btnExport_Click(object sender, EventArgs e)
    {
        List<Tb_AgreementInfo> list;
        list = tam.GetModelList("1=1");
        this.gvCAStatics.DataSource = list;
        this.gvCAStatics.DataBind();
        CreateExcel(list, "ConFulfilStatics.xls");
    }


    /// <summary>
    ///  
    /// </summary>
    /// <param name="list"></param>
    /// <param name="FileName"></param>
    /// *** 12.12
    public void CreateExcel(List<Tb_AgreementInfo> list, string FileName)
    {
        HttpResponse resp;
        resp = Page.Response;
        resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName);
        string colHeaders = "", ls_item = "";
        //  
        colHeaders += " " + "\t";
        colHeaders += " " + "\t";
        colHeaders += " " + "\t";
        colHeaders += " " + "\t";
        colHeaders += " " + "
"; resp.Write(colHeaders); // foreach (Tb_AgreementInfo custom in list) { ls_item += custom.AreementName + "\t"; ls_item += custom.AreementType==0?" ":" " + "\t"; ls_item += custom.YuetCommissarial + "\t"; ls_item += custom.SubsceibeDate + "\t"; ls_item += custom.IsAduiting == 0 ? " " : " " + "
"; // HTTP , ls_item resp.Write(ls_item); ls_item = ""; } // HTTP resp.End(); }

좋은 웹페이지 즐겨찾기