Creating multiple tables for Word.Table using C#

Discussion in 'ASP .Net' started by nish, Feb 25, 2005.

  1. nish

    nish Guest

    Hi,

    I am struggling with this code. I am trying to create 3 separate
    tables and print them in word, however I end up with 1 big table and 1
    nested table inside and 1 more nested table within that.

    Here is my code..

    // CALL CreateTable - see method below
    Word.Table oTable = CreateTable();

    // Return with created table and add cell items
    for (int y=0; y < dt.Columns.Count; y++)
    {
    for (int z=1; z <= 2; z++)
    {
    if (z == 1)
    oTable.Cell(y,z).Range.Text = dt.Columns[y].ColumnName;
    else
    oTable.Cell(y,z).Range.Text = dt.Rows[x][y].ToString();
    }
    }




    private Word.Table CreateTable()
    {
    // Create Table
    object oTableBehavior =
    Word.WdDefaultTableBehavior.wdWord9TableBehavior;
    object oFitBehavior = Word.WdAutoFitBehavior.wdAutoFitFixed;


    Word.Table oTable = oDoc.Tables.Add(oWord.Selection.Range, 24, 2,
    ref oTableBehavior, ref oFitBehavior);


    //Set table properties
    object oStyle = "Table Grid";
    oTable.set_Style(ref oStyle);

    return oTable;
    }


    Please advise...
    I am saving and activating this....



    oDoc.SaveAs(ref fileName, ref oMissing, ref oMissing, ref oMissing,
    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
    oMissing,
    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
    oMissing, ref oMissing, ref oMissing);

    oDoc = oWord.Documents.Open(ref fileName, ref oMissing, ref
    readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
    oMissing, ref oMissing, ref oMissing, ref oMissing, ref isVisible, ref
    oMissing, ref oMissing, ref oMissing, ref oMissing);
    oWord.ShowMe();

    oDoc.Activate();

    // Exit out of word
    oWord.Quit(ref oMissing, ref oMissing, ref oMissing);


    Many thanks,
    Nisha
     
    nish, Feb 25, 2005
    #1
    1. Advertising

  2. nish

    mthakershi

    Joined:
    Aug 8, 2006
    Messages:
    2
    Multiple nested tables issue

    Hi Nisha,

    Your post is more than a year old, but I am having issues in creating nested tables (2 levels) in C#/MS Word. Could you please reply if you have anything that can help me?

    Appreciate it.

    Malay
     
    mthakershi, Aug 8, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. m3ckon
    Replies:
    3
    Views:
    3,526
    m3ckon
    Aug 5, 2004
  2. Daves
    Replies:
    1
    Views:
    643
    S. Justin Gengo
    Jan 6, 2006
  3. Replies:
    4
    Views:
    490
  4. John Meyer

    Creating a form off of multiple tables

    John Meyer, Sep 24, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    455
    Jon Paal
    Sep 25, 2006
  5. darrel
    Replies:
    0
    Views:
    408
    darrel
    Jan 30, 2007
Loading...

Share This Page