c#office word interop get table style

时间:2014-01-24 19:21:02

标签: c# ms-word office-interop

我想在现有的word文档中找到某种样式,并用另一种表格样式替换某种表格样式。当我试图从桌子上获取风格时,它并不是有意义的。

例如,当我将样式输出到控制台时,它返回“System .__ ComObject”。我想要“Table Classic 2”这样的东西,这样我就可以进行比较,然后设置合适的风格。

这是我的测试代码:

Word.Application oWord = new Word.Application();
                oWord.Visible = true;
                Console.WriteLine("Word.Application is started");

                object fileName = @"G:\test.docx";

                Word.Document oDoc = oWord.Documents.Open(ref fileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);

                Word.Table oTable = oDoc.Tables[1];
                //oTable.set_Style("Table Classic 2");
                Console.WriteLine( "table style" + oTable.get_Style());

1 个答案:

答案 0 :(得分:1)

因为没有人回答我的问题。我试图在VBA中这样做,这就是我所拥有的:

For Each objtable In ActiveDocument.Tables

        If objtable.Style = "Table Grid" Then
            objtable.Style = "Grid Table 4"
        End If

Next