none
Docx file to treeview RRS feed

  • Question

  • hi all,

     

    i have a word file,i can able to read word file .But my need is to convert this word file into treeview.Tree view should like outline mode in word document(open docx file and go to the view tab and click on the outline).How can we achieve this??? 

     

     

       Microsoft.Office.Interop.Word.Application wordapp = new Microsoft.Office.Interop.Word.Application();

            object file = Server.MapPath("~/Upload/Sample Document.docx");

            object NullObject = System.Reflection.Missing.Value;

            object FalseValue = false;

            object TrueValue = true;

            Microsoft.Office.Interop.Word.Document Document1 = wordapp.Documents.Open(file, ref NullObject, ref FalseValue, ref NullObject, ref NullObject, ref NullObject, ref TrueValue, ref NullObject, ref NullObject, ref NullObject, ref NullObject, ref NullObject, ref NullObject, ref NullObject, ref NullObject, ref NullObject);

            string s = Document1.Content.Text;

            Document1.Close(ref NullObject, ref NullObject, ref NullObject);

    thanks in advance

    jeffrey k

    • Moved by CoolDadTx Thursday, July 21, 2011 1:44 PM Office related (From:Visual C# General)
    Thursday, July 21, 2011 6:32 AM

All replies

  • hai,

    this is for online bible.They can upload word document.I have to convert into books name->Chapter->Words->sub-words as tree structure.I have converted into xml.But it not proper format .

    Friday, July 22, 2011 6:00 AM
  • Hi Jeffrey

    This is a difficult question as you don't provide any information on how your program can recognize what content belongs to which outline level.

    Basically, you need to assign an outline level to each paragraph that's part of the hierarchy. The OulineLevel property belongs to the Paragraph object and accepts an Enum value of Word.WdOutlineLevel - there are nine Enums. So it could look something like:

      Document1.Paragraphs[1].OutlineLevel = Word.WdOutlineLevel.wdOutlineLevel1;

    Outline levels are assigned automatically if you apply one of Word's built-in Heading styles to a paragraph.

    At this point, that's about all I can tell you.


    Cindy Meister, VSTO/Word MVP
    Friday, July 22, 2011 6:45 AM
    Moderator