本文介绍了如何在可编辑模式下将gridview导出到msword的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个与数据库绑定的gridview.必须以可编辑模式将此gridview导出到msword.我有msword-2007. >

hi all,

i have a gridview which is bounded with the database. have to export this gridview to msword in editable mode.i have msword-2007.I had tried the following way but it produced a saved word file and produced an error on opening "word cannot start the converter mswrd32.wpc".

DataSet ds = new DataSet();
ds=obj_bal.BAL_ShowFrom_Reply();
GridView1.DataSource = ds;
GridView1.DataBind();
Response.AppendHeader("Content-Type", "application/vnd.ms-word");
Response.AddHeader("Content-Disposition","test.docx");
Response.Write(DropDownList1.Text);
Response.End();

推荐答案

DataSet ds = new DataSet();
ds=obj_bal.BAL_ShowFrom_Reply();
GridView1.DataSource = ds;
GridView1.DataBind();

Response.Clear();
Response.ClearHeaders();
Response.AddHeader("content-disposition", "attachment;filename=test.docx");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.word";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
HtmlForm frm = new HtmlForm();
GridView1.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(GridView1);
frm.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();


这篇关于如何在可编辑模式下将gridview导出到msword的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 04:49