简体   繁体   English

使用C Sharp在单词自动选择中选择所有形状

[英]Select all shapes in word automation with C sharp

How can I select all shapes in a document with C#. 如何使用C#选择文档中的所有形状。

I'm currently changing the language settings of a word document. 我目前正在更改Word文档的语言设置。

I was able to change the language using select all, unfortunately not all were selected like header/footer, text box or any shapes on the document. 我可以使用全选来更改语言,但是不幸的是,并未选择全部,例如页眉/页脚,文本框或文档上的任何形状。 I manage somehow to set the language in header/footer. 我设法以某种方式在页眉/页脚中设置语言。 But I can't find a way to set the language for shapes. 但是我找不到一种设置形状语言的方法。

I have tried to do a quick macro, but I don't know what the index for each shapes in the document. 我试图做一个快速宏,但是我不知道文档中每个形状的索引是什么。

This is the macro: 这是宏:

ActiveDocument.Shapes("Text Box 4").Select
ActiveDocument.Shapes.Range(Array("Text Box 4", "Rectangle 7")).Select
ActiveDocument.Shapes.Range(Array("Text Box 4", "Rectangle 7", _
    "Text Box 10")).Select
ActiveDocument.Shapes.Range(Array("Text Box 4", "Rectangle 7", _
    "Text Box 10", "Rectangle 11")).Select
Selection.LanguageID = wdEnglishUK

And this is what I deed in C#, but its not working... 这就是我在C#中所做的,但是它不起作用...

        wordApp.ActiveDocument.Shapes.SelectAll();
        wordApp.Selection.LanguageID = Word.WdLanguageID.wdEnglishUK;

If try using this: 如果尝试使用此:

wordApp.ActiveDocument.Shapes.Range(??).Select; //I don't know what should I put inside the range
wordApp.Selection.LanguageID = Word.WdLanguageID.wdEnglishUK;

I hope someone here can help me. 我希望这里有人可以帮助我。 Or if you have better solution to change the language, please let me know.Tnx 或者,如果您有更好的解决方案来更改语言,请告诉我.Tnx

You have not had an answer in a while, so here is VBA, I hope you can convert it. 您有一段时间没有答案了,所以这是VBA,希望您可以转换它。

This one takes care of language change for the whole document, including headers and footers and other "stories", and text boxes as well as shapes with text. 这个负责整个文档的语言更改,包括页眉和页脚以及其他“故事”,文本框以及带有文本的形状。

Sub langconvPL()
Dim mystoryrange As Range
For Each mystoryrange In ActiveDocument.StoryRanges
mystoryrange.LanguageID = wdPolish
mystoryrange.NoProofing = False
Next mystoryrange

scount = ActiveDocument.Shapes.Count

For x = 1 To scount
ActiveDocument.Shapes(x).Select
If ActiveDocument.Shapes(x).TextFrame.HasText = True Then
ActiveDocument.Shapes(x).TextFrame.TextRange.Select
Selection.LanguageID = wdPolish
End If
Next x
End Sub

From: http://www.proz.com/forum/office_applications/31516-how_to_change_textbox_language_in_a_word_document.html 来源: http//www.proz.com/forum/office_applications/31516-how_to_change_textbox_language_in_a_word_document.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM