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)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 云浮市| 上饶市| 巨野县| 海林市| 孝昌县| 北宁市| 镇巴县| 东平县| 色达县| 平定县| 章丘市| 丰城市| 万山特区| 梅河口市| 普格县| 平南县| 乌兰县| 永宁县| 泾源县| 浦县| 黎川县| 浦城县| 新建县| 南召县| 青浦区| 肃北| 纳雍县| 钟祥市| 马尔康县| 云梦县| 吴桥县| 措勤县| 阜南县| 石河子市| 正阳县| 皮山县| 屯留县| 民县| 麟游县| 萨迦县| 读书|