VSTO를 사용하여 WordDocument의 모든 ContentControls (Header, Footers, TextBoxes의 ContentControls 포함)를 찾을 수있는 방법이 있습니까?VSTO Word 문서의 ContentControls를 찾습니다.
머리글/바닥 글 안의 주 문서의 ContentControl 만 반환합니다.
VSTO를 사용하여 WordDocument의 모든 ContentControls (Header, Footers, TextBoxes의 ContentControls 포함)를 찾을 수있는 방법이 있습니까?VSTO Word 문서의 ContentControls를 찾습니다.
머리글/바닥 글 안의 주 문서의 ContentControl 만 반환합니다.
이 시도 :
foreach (Word.ContentControl contentcontrol in this.Application.ActiveDocument.ContentControls)
{
//Some action on all contentcontrol objects
}
을 그는 내가 같은 문제를 처리하고있어 문서의 StoryRanges
하지만,이 말씀을 운전에 (contentcontrols에 대한) 모든 범위에 반복하려고 작동하지 않는 경우 MATLAB에서. 워드 MVP로이 페이지는 나를 위해 문제를 해결 :
http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm
은 본질적으로, 당신은에 있습니다
는 http://social.msdn.microsoft.com/Forums/is/vsto/thread/0eb0af6f-17db-4f98-bc66-155db691fd70
public static List<ContentControl> GetAllContentControls(Document wordDocument)
{
if (null == wordDocument)
throw new ArgumentNullException("wordDocument");
List<ContentControl> ccList = new List<ContentControl>();
// The code below search content controls in all
// word document stories see http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm
Range rangeStory;
foreach (Range range in wordDocument.StoryRanges)
{
rangeStory = range;
do
{
try
{
foreach (ContentControl cc in rangeStory .ContentControls)
{
ccList.Add(cc);
}
foreach (Shape shapeRange in rangeStory.ShapeRange)
{
foreach (ContentControl cc in shapeRange.TextFrame.TextRange.ContentControls)
{
ccList.Add(cc);
}
}
}
catch (COMException) { }
rangeStory = rangeStory.NextStoryRange;
}
while (rangeStory != null);
}
return ccList;
}
에서 복사