使用互操作在 word 中创建重复行

Create repeating rows in word using interop

我有以下代码

string html  = @"<table>
<tr>
<td>Column1</td>
<td>Column2</td>
</tr>
<tr>
<td>Column1 Data</td>
<td>Column 2 Data</td>
</tr></table>";

这只是一个包含 html table 的字符串(我实际拥有的那个非常大,我从存储过程中获取它)

下面的代码读取这个 html 字符串并将其插入到 word 文档中

public static bool CreateFormattedWord(string html)
    {
        Application wordApp = new Application();       
        wordApp.Visible = true;
        Document doc = wordApp.Documents.Add();      
        object missing = Type.Missing;
        ContentControl contentControl = doc.ContentControls.Add(WdContentControlType.wdContentControlRichText, ref missing);     
        contentControl.Range.InsertFile(SaveToTemporaryFile(html), ref missing, ref missing, ref missing, ref missing);       

        Console.Read();
        return true;
    }

    public static string SaveToTemporaryFile(string html)
    {
        string htmlTempFilePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), string.Format("{0}.html", System.IO.Path.GetRandomFileName()));
        using (StreamWriter writer = File.CreateText(htmlTempFilePath))
        {
            html = string.Format("<html>{0}</html>", html);
            writer.WriteLine(html);
        }
        return htmlTempFilePath;
    }

我可以转到创建的 word 文档 select 我插入的 table 并转到布局并单击重复 Table header 它会重复文件。

我如何在现有代码中使用 Interop 实现相同的功能,以便在将 table 插入文档时重复 Table header?

 var tableID = doc.Tables[1];
   tableID.Rows[1].HeadingFormat = -1; 

上面的代码似乎可以解决问题

我从两个链接得到了答案