'Export HTML to MS WORD docx file in ASP.NET
I want to export html Table on my aspx page to MS WORD (.docx) file. I already have code to export .doc file but I want to Export in docx extension.
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();
}
Solution 1:[1]
put
Response.AddHeader("Content-Disposition", "attachment; filename=WORK_ORDER.docx");
instead of
Response.AddHeader("Content-Disposition", "attachment; filename=WORK_ORDER.doc");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bahman_Aries |
