把dgrd写入word时打不开word文档(一直在线等)
我想把dgrd里的数据写到word中并保存,用的是下面的一段代码,可是保存完后却打不开那个word文档,提示有人在使用,重启电脑后还是提示有人在使用。用word2000的只读打开该文档则出错,word关闭。有人知道是什么原因吗?还有,用下面这段代码是把dgrd里的所有东西都写进word里吗?我想选择一部分该怎么办?word中显示的格式是怎样的?我第一次往word里写东西,什么都不懂,各位老大多帮忙!
public void ToWord(System.Web.UI.Control ctl) {
Response.Clear();
Response.Buffer = true;
Response.Charset="GB2312";
Response.AppendHeader("Content-Disposition","attachment;filename=word.doc");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-word";
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
ctl.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
this.dgrdMemorabilia.ShowHeader = false;
this.dgrdMemorabilia.ShowFooter = false;
Response.Flush();
Response.Close();
Response.End();
Word.Application app = new Word.ApplicationClass();
app.Visible = true;
}