word2007 read doc/docx question RRS feed

  • Question

  • When you read (*.doc/*.docx) Word files, how to judge the contents of reading is text, tables or images?
    my code:
     oDoc = CreateWordDocument(filePath, HideWin);
     string readText = "";
     for (int i = 0; i < oDoc.Paragraphs.Count; i++)
          readText += oDoc.Paragraphs[i].Range.Text;

    • Edited by White_Xie Thursday, October 13, 2011 8:44 AM
    Thursday, October 13, 2011 8:43 AM


  • Hi Xie

    The exact code you show us will read only text because you use the Range.Text property.

    The Range.get_Information(Word.WdInformation.wdWithinTable) can tell you whether a particular range is within a table structure.

    if Range.InlineShapes.Count > 0 then the Range object includes an InlineShape.

    If Range.ShapeRange.Count > 0 then a Shape object is anchored within that Range, although it will not actually "include" the Shape. (A Shape is a graphic object that has text flow formatting.)

    Cindy Meister, VSTO/Word MVP
    • Marked as answer by White_Xie Friday, October 14, 2011 3:12 AM
    Thursday, October 13, 2011 12:45 PM