我正在使用以下代码将html字符串输出到带有.docx扩展名的word文档中[不是.doc]
private void ExportBodyAsDoc(string strBody) {
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "Application/msword";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=myfile.docx");
var repo = new System.IO.MemoryStream();
var stringBytes = System.Text.Encoding.UTF8.GetBytes(strBody);
repo.Write(stringBytes, 0, strBody.Length);
HttpContext.Current.Response.BinaryWrite(repo.ToArray());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
HttpContext.Current.Response.End();
}
它仅与 Firefox 一起使用,而在其他情况下它正在破坏文档。