Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 需要支持使用StringBuilder生成word文档_C#_Html_Stringbuilder - Fatal编程技术网

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()
时,在这种情况下如何创建文档。请查看编辑后的代码。