我需要将我的 html 页面转换并下载为 word(.docx) 文档。我能够转换为文档格式。但是转换为 docx 格式会损坏文件。
我的代码是
Response.ClearContent();
Response.Buffer = false;
Response.ContentType = "application/vnd.word";
Response.ContentEncoding = System.Text.Encoding.Default;
string date = DateTime.Now.ToString("hh-mm-ss");
Response.AddHeader("Content-Disposition", "attachment; filename=Newdoc.doc");
Response.Charset = "";
Response.Write("<html><head></head><body>");
Response.Write("My html data");
Response.Write("</body></html>");
Response.ClearContent();
Response.Flush();
Response.Close();
Response.End();