C# 需要支持使用StringBuilder生成word文档
我正在尝试使用C# 需要支持使用StringBuilder生成word文档,c#,html,stringbuilder,C#,Html,Stringbuilder,我正在尝试使用StringBuilder生成word文档,如下所示 [WebMethod] public static void ExportToWord(string HTMLContent) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Charset = ""; HttpContext.Current.Response.Con
StringBuilder
生成word文档,如下所示
[WebMethod]
public static void ExportToWord(string HTMLContent)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/msword";
string strFileName = "GenerateDocument" + ".doc";
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);
System.Text.StringBuilder strHTMLContent = new System.Text.StringBuilder();
strHTMLContent.Append(HTMLContent);
HttpContext.Current.Response.Write(strHTMLContent);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();
}
问题是当我看到下载的文档时,它的剩余页面内容添加了上述
内容我缺少响应。在开头清除,在结尾清除Response.End()
。感谢您的响应。当我使用jquery调用ExportToWord()
时,在这种情况下如何创建文档。请查看编辑后的代码。