在ASP.NET中将HTML导出到MS WORD docx文件

时间:2013-11-07 13:04:43

标签: c# html asp.net ms-word

我想将我的aspx页面上的html表导出到MS WORD( .docx )文件。 我已经有了导出 .doc 文件的代码,但我想在docx扩展名中导出。

protected void btnExport_Click(object sender, EventArgs e)
{
    Response.Clear();
    Response.Buffer = true;
    Response.ContentType = "application/vnd.openxmlformatsofficedocument.wordprocessingml.documet";
    Response.AddHeader("Content-Disposition", "attachment; filename=WORK_ORDER.doc");
    Response.ContentEncoding = System.Text.Encoding.UTF8;
    Response.Charset = "";
    EnableViewState = false;
    System.IO.StringWriter writer = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter html = new System.Web.UI.HtmlTextWriter(writer);
    xx.RenderControl(html);
    Response.Write(writer);
    Response.End();
}      

1 个答案:

答案 0 :(得分:0)

Response.AddHeader("Content-Disposition", "attachment; filename=WORK_ORDER.docx");

而不是

Response.AddHeader("Content-Disposition", "attachment; filename=WORK_ORDER.doc");