开发者

Adding a Row to Table of Late Bound MS Word

I do need to add a row to a table on late bounded MS Word. Please see my code here...

On code you can see I have to implement code for function public void AddNewRow(int tableId).

Here I do need to add a new BLANK row, since the row count I am going to add to table vary depending on DataSet.

Any idea how to 开发者_C百科do it... ? Better if you can share code...

(Other ares of code working perfectly)

I am using .Net Version 2.0


I found answer my self, think this will be helpful to you all...

public void AddNewRow(int tableId, int rowCount)
    {
        object[] oParams = new object[1];
        oParams[0] = tableId;
        object table_ = tables.GetType().InvokeMember("Item",
        BindingFlags.InvokeMethod,
        null,
        tables,
        oParams);
        object rows = table_.GetType().InvokeMember("Rows",
        System.Reflection.BindingFlags.GetProperty,
        null,
        table_,
        null);
        oParams = new object[1];
        if (rowCount == 1)
        {
            object row = rows.GetType().InvokeMember("Add",
            BindingFlags.InvokeMethod,
            null,
            rows,
            null);
        }
        else
        {
            for (int i = 0; i < rowCount; i++)
            {
                object row = rows.GetType().InvokeMember("Add",
            BindingFlags.InvokeMethod,
            null,
            rows,
            null);
            }
        }
    }


Table table = tables[tableid];

  for (int i = 0; i < 20; i++) // I took it 20 just for example
   {
     Row row = table.Rows.Add();                   
   }

Refer to following link for more info

http://jgvimalan.wordpress.com/2011/02/08/add-rows-to-table-in-ms-word-document-using-c/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜