posts - 1,  comments - 4,  trackbacks - 0
          在Asp.net中將GridView打印為word或者Excel

          學到的新東東,GridView打印為word,呵呵

          1.打印按鈕函數
          1
          2
          3
          4
          5
          6
          7
          8
          9
          10
          11
          12
          13
          14
          15
          16
           protected void Button_print_Click(object sender, EventArgs e)
              {
                  System.Web.HttpContext HC = System.Web.HttpContext.Current;
                  HC.Response.Clear();
                  HC.Response.Charset = "GB2312";
                  HC.Response.Buffer = true;
                  HC.Response.ContentEncoding = System.Text.Encoding.UTF7;
                  HC.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("查詢結果打印", System.Text.Encoding.UTF8) + ".doc");
                  HC.Response.ContentType = "application/ms-word";//如果要打印為excel格式,則換為"application/excel"
                  this.EnableViewState = false;
                  System.IO.StringWriter sw = new System.IO.StringWriter();
                  System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
                  this.GV_result.RenderControl(htw);
                  HC.Response.Write(sw.ToString());
                  HC.Response.End();
              }//打印輸出按鈕
          


          2.必須再寫這個函數
          1
          2
          3
            public override void VerifyRenderingInServerForm(System.Web.UI.Control control)
              {
              }
          


          3.在.aspx頁面page里邊加上
          1
            EnableEventValidation="false"
          


          上面這三步是必須的
          文章來源:http://lan0725.blog.chinajavaworld.com/entry/7031/0/
          posted on 2008-12-17 11:05 Elan 閱讀(1225) 評論(1)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 梧州市| 高陵县| 武胜县| 维西| 潞西市| 金平| 江西省| 博兴县| 辽阳县| 灵川县| 遂溪县| 江华| 廊坊市| 翼城县| 阳原县| 宁城县| 古浪县| 西乡县| 托里县| 万山特区| 青海省| 惠州市| 河间市| 澄城县| 绥棱县| 德钦县| 金门县| 江孜县| 仪征市| 临武县| 泊头市| 怀宁县| 越西县| 乌苏市| 辽阳市| 和龙市| 扬州市| 岳西县| 伊金霍洛旗| 宝坻区| 无锡市|