0

次のコードを使用して、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でのみ動作しています。

4

1 に答える 1

0

おそらく、出力のコンテンツ エンコーディングを設定する必要があります。

UTF8 を使用しているため、次のように動作するはずです。

HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;

http://msdn.microsoft.com/en-us/library/system.web.httpresponse.contentencoding.aspx http://msdn.microsoft.com/en-us/library/system.text.encoding.utf8.aspx

于 2013-07-08T15:23:48.457 に答える