我想将 GridView 中的数据输入到 Word 文档中并从客户端下载它
var gd = new GridView
{
DataSource = li,
AutoGenerateColumns = true,
};
gd.DataBind();
if (gd.Rows.Count > 0)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + "List" + DateTime.Now.ToString("dd.MM.yyyy") + ".doc");
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-word";
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());
var oStringWriter = new System.IO.StringWriter();
var oHtmlTextWriter = new HtmlTextWriter(oStringWriter);
gd.RenderControl(oHtmlTextWriter);
HttpContext.Current.Response.Output.Write(oStringWriter.ToString());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
错误(换行):
Sys.WebForms.PageRequestManagerParserErrorException:
Sys.WebForms.PageRequestManagerParserErrorException:
The message received from the server could not be parsed.' when calling method:
[nsIDOMEventListener::handleEvent]
[Break On This Error]
Filtered chrome url chrome://firebug/content/net/spy.js
spy.js (line 807)
<System>
var gd = new GridView
{
DataSource = li,
AutoGenerateColumns = true,
};
gd.DataBind();
if (gd.Rows.Count > 0)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + "List" + DateTime.Now.ToString("dd.MM.yyyy") + ".doc");
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-word";
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());
var oStringWriter = new System.IO.StringWriter();
var oHtmlTextWriter = new HtmlTextWriter(oStringWriter);
gd.RenderControl(oHtmlTextWriter);
HttpContext.Current.Response.Output.Write(oStringWriter.ToString());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
ERROR (lines wrapped):
Sys.WebForms.PageRequestManagerParserErrorException:
Sys.WebForms.PageRequestManagerParserErrorException:
The message received from the server could not be parsed.' when calling method:
[nsIDOMEventListener::handleEvent]
[Break On This Error]
Filtered chrome url chrome://firebug/content/net/spy.js
spy.js (line 807)
<System>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: