导出word文档

string id = Request["id"];
            if (string.IsNullOrEmpty(id))
            {
                Response.Write("参数有误!!!");
                return;
            }

Model = db.FirstOrDefault<Job>("select * from dt_Job where Id=@0", id);
            if (Model==null)
            {
                Response.Write("记录不存在!!!");
                return;
            }

Response.Clear();
            Response.Buffer = true;
            Response.Charset = "GB2312";
            //this.EnableViewState = false;
            Response.AppendHeader("Content-Disposition", "attachment;filename="+Model.Name+".doc");
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文   
            Response.ContentType = "application/ms-word";//设置输出文件类型为word文件
            
            //wdTab.Rows.Alignment = Word.WdRowAlignment.wdAlignRowCenter;
            System.IO.StringWriter tw = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
            this.Panel1.RenderControl(hw);
            Response.Write(tw.ToString());
            Response.End();

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

操作流程:

1、清除缓存区流中的所有内容的输出。Response.Clear()

2、声明缓冲输出。Response.Buffer = true

3、设置输出流编码。Response.Charset = "GB2312"

4、添加输出流。Response.AppendHeader("Content-Disposition", "attachment;filename="+Model.Name+".doc");

5、设置输出流位简体中文。Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");

6、设置输出文件类型为word文件。

7、

上一篇:HBase二级索引的设计


下一篇:HBase二级索引、读写流程