乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      asp.net導(dǎo)出excel

       一塘靜月 2009-06-01

      下面這種方法只能導(dǎo)出頁面的Html至Excel:

       1     public static void GridExportExcel(ref System.Web.UI.WebControls.GridView dg, string fileName)
       2     {
       3         System.Web.HttpContext.Current.Response.Clear();
       4         System.Web.HttpContext.Current.Response.Buffer = true;
       5         System.Web.HttpContext.Current.Response.Charset = "GB2312"//設(shè)置了類型為中文防止亂碼的出現(xiàn) 
       6         System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition""attachment;filename=" + fileName + ".xls"); //定義輸出文件和文件名 
       7         System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//設(shè)置輸出流為簡體中文 
       8         System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";//設(shè)置輸出文件類型為excel文件。 
       9         dg.Page.EnableViewState = false;
      10         System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN"true);
      11         System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
      12         System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
      13         dg.RenderControl(oHtmlTextWriter);
      14         System.Web.HttpContext.Current.Response.Write(oStringWriter.ToString());
      15         System.Web.HttpContext.Current.Response.End();
      16     }

      當(dāng)要從DataSet導(dǎo)出至Excel,則用如下方法:
        1    protected void btn_out_Click(object sender, EventArgs e)
        2    {
        3        DataSet ds;
        4        if ((bool)ViewState["PageIndexChange"== false)
        5        {
        6            Response.Write("<script>alert('對不起,沒有查詢到任何記錄,不能導(dǎo)出數(shù)據(jù)')</script>");
        7            return;
        8        }

        9        if ((int)Session["userTeam"> 0)
       10        {
       11            if (ViewState["toolTip"].ToString().CompareTo("部門"== 0)
       12            {
       13                ds = rd.GetDeptAttenInfo((string)Session["enterId"], (string)ViewState["strValue"],
       14            (DateTime)ViewState["FromTime"], (DateTime)ViewState["ToTime"], (int)ViewState["ShiftResult"], (int)ViewState["DeptChk"], (int)ViewState["AdminChk"]);
       15            }

       16            else
       17            {
       18                ds = rd.GetUserAttenInfo(int.Parse(ViewState["strValue"].ToString()),
       19            (DateTime)ViewState["FromTime"], (DateTime)ViewState["ToTime"], (int)ViewState["ShiftResult"], (int)ViewState["DeptChk"], (int)ViewState["AdminChk"]);
       20            }

       21        }

       22        else
       23        {
       24            ds = rd.GetUserAttenInfo(int.Parse(ViewState["strValue"].ToString()),
       25            (DateTime)ViewState["FromTime"], (DateTime)ViewState["ToTime"], (int)ViewState["ShiftResult"], (int)ViewState["DeptChk"], (int)ViewState["AdminChk"]);
       26        }

       27        CreateExcel(ds, "1""outExcel");
       28        //if (this.gvUser.Rows[0].Cells[0].Text == "" || this.gvUser.Rows[0].Cells[0].Text == "沒有查到數(shù)據(jù)")
       29        //{
       30        //    Response.Write("<script>alert('對不起,沒有查詢到任何記錄,不能導(dǎo)出數(shù)據(jù)')</script>");
       31
       32        //}
       33        //else
       34        //{
       35        //    GridExportExcel(ref this.gvUser, "刷卡記錄");
       36        //}
       37    }

       38    public void CreateExcel(DataSet ds, string typeid, string FileName)
       39    {
       40        HttpResponse resp;
       41        resp = Page.Response;
       42        resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
       43        resp.AppendHeader("Content-Disposition""attachment;filename=" + FileName + ".xls");
       44        resp.ContentType = "application/ms-excel";
       45        string colHeaders = "", ls_item = "";
       46
       47        //定義表對象與行對像,同時用DataSet對其值進(jìn)行初始化 
       48        DataTable dt = ds.Tables[0];
       49        DataRow[] myRow = dt.Select("");
       50        // typeid=="1"時導(dǎo)出為EXCEL格式文件;typeid=="2"時導(dǎo)出為XML格式文件 
       51        if (typeid == "1")
       52        {
       53            //取得數(shù)據(jù)表各列標(biāo)題,各標(biāo)題之間以\t分割,最后一個列標(biāo)題后加回車符 
       54            //for (i = 0; colHeaders += dt.Columns[i].Caption.ToString() + "\t";
       55            //colHeaders += dt.Columns[i].Caption.ToString() + "\n")
       56            //    //向HTTP輸出流中寫入取得的數(shù)據(jù)信息 
       57            //    resp.Write(colHeaders);
       58            //逐行處理數(shù)據(jù)
       59            for (int i = 0; i < gvUser.Columns.Count; i++)
       60            {
       61                if (i != 0 && i != 13 && i != 14 && i != 15)
       62                {
       63                    ls_item += this.gvUser.Columns[i].HeaderText + "\t";
       64                    //ls_item += row[i].ToString() + "\n";
       65                    //當(dāng)前行數(shù)據(jù)寫入HTTP輸出流,并且置空ls_item以便下行數(shù)據(jù)     
       66                }

       67            }

       68            ls_item = ls_item.TrimEnd(new char[] '\t' });
       69            ls_item += "\n";
       70            resp.Write(ls_item);
       71            ls_item = "";
       72            foreach (DataRow row in myRow)
       73            {
       74                //在當(dāng)前行中,逐列獲得數(shù)據(jù),數(shù)據(jù)之間以\t分割,結(jié)束時加回車符\n 
       75                for (int i = 0; i < gvUser.Columns.Count; i++)
       76                {
       77                    if (i != 0 && i != 13 && i != 14 && i != 15)
       78                    {
       79                        if (i == 3)
       80                        {
       81                            ls_item += ((DateTime)row[((BoundField)this.gvUser.Columns[i]).DataField]).ToString("yyyy年MM月dd日"+ "\t";
       82                        }

       83                        else
       84                        {
       85                            ls_item += row[((BoundField)this.gvUser.Columns[i]).DataField].ToString() + "\t";//this.gvUser.Columns[i].HeaderText
       86                        }
         
       87                    }

       88                }

       89                ls_item = ls_item.TrimEnd(new char[] '\t' });
       90                ls_item += "\n";
       91                resp.Write(ls_item);
       92                ls_item = "";
       93            }

       94        }

       95        //else
       96        //{
       97        //    if (typeid == "2")
       98        //    {
       99        //        //從DataSet中直接導(dǎo)出XML數(shù)據(jù)并且寫到HTTP輸出流中 
      100        //        resp.Write(ds.GetXml());
      101        //    }
      102        //}
      103        //寫緩沖區(qū)中的數(shù)據(jù)到HTTP頭文件中 
      104        resp.End();
      105    }

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多