2011-11-25 1 views
1

Word 문서의 모든 ContentControl을 가져오고 싶습니다. 현재 나는 이것을하기 위해 다음과 같은 함수를 사용한다.COM Word -> 모든 ContentControls 가져 오기

private static List<ContentControl> GetAllContentControls(Document wordDocument) 
    { 
     if (null == wordDocument) 
      throw new ArgumentNullException("wordDocument"); 

     List<ContentControl> ccList = new List<ContentControl>(); 

     Range rangeStory; 
     foreach (Range range in wordDocument.StoryRanges) 
     { 
      rangeStory = range; 
      do 
      { 
       try 
       { 
        foreach (ContentControl cc in rangeStory.ContentControls) 
        { 
         ccList.Add(cc); 
        } 
       } 
       catch (COMException) { } 
       rangeStory = rangeStory.NextStoryRange; 

      } 
      while (rangeStory != null); 
     } 
     return ccList; 
    } 

문제는 텍스트 필드에도 Contentcontrols를 가져 오는 것입니다.

답변

0

나는 그것을

private static List<ContentControl> GetAllContentControls(Document wordDocument) 
    { 
     if (null == wordDocument) 
      throw new ArgumentNullException("wordDocument"); 

     List<ContentControl> ccList = new List<ContentControl>(); 

     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; 
    } 
있어