none
I Don't Want Nested Tables! (C#, Word) RRS feed

  • Question

  • Hi, I'm going to high school in Turkey.
    My English is reaally bad but i'm thinking i can explain my problem.

    I'm creating word document in Visual Studio 13 and adding a table.
    But after if i want open again this document and add a table...
    Tables being nested.

    I want add tables but without nested.

    I'm sorry for my English!

    Codes;

                        wordApp.Selection.Font.Size = 9;
                        wordApp.Selection.Font.Name = "Times New Roman";
                        object oTableBehavior = Word.WdDefaultTableBehavior.wdWord9TableBehavior;
                        object oFitBehavior = Word.WdAutoFitBehavior.wdAutoFitContent;
                        Word.Table oTable = aDoc.Tables.Add(aDoc.Range(0,0), 3, 1, ref oTableBehavior, ref oFitBehavior);
                        oTable.Cell(1, 1).Range.Text = adsoy;
                        oTable.Cell(2, 1).Range.Text = sınnum;
                        oTable.Cell(3, 1).Range.Text = sıra.ToString();

    Can you help me!



    • Edited by SerVians Wednesday, March 1, 2017 8:38 PM
    Wednesday, March 1, 2017 8:35 PM

All replies

  • Hi SerVians,
    >>Word.Table oTable = aDoc.Tables.Add(aDoc.Range(0,0), 3, 1, ref oTableBehavior, ref oFitBehavior);
    You use the same range all the time,so office will insert the table to the same location,as a result,
    the tables will be nested.I suggest you to change the range dynamicly.
    Here is a sample
    Word.Range rng = wordApp.Selection.Range; 
    Word.Table oTable = aDoc.Tables.Add(rng, 3, 1, ref oTableBehavior, ref oFitBehavior);

    It will insert the table where the mouse selects.
     
    Best regards,
    Terry

    Thanks
    Thursday, March 2, 2017 6:15 AM