我确实需要在后期有界MS Word的表格中添加一行。请参阅我的代码here ...
在代码中,您可以看到我必须实现函数public void AddNewRow(int tableId)
的代码。
这里我需要添加一个新的BLANK行,因为我要添加到表中的行数因DataSet而异。
知道怎么做......?如果你可以分享代码,那就更好了......
(其他代码完美无缺的工作)
我正在使用.Net Version 2.0
答案 0 :(得分:2)
我找到了自己的答案,认为这对你们所有人都有帮助......
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);
}
}
}
答案 1 :(得分:-1)
Table table = tables[tableid];
for (int i = 0; i < 20; i++) // I took it 20 just for example
{
Row row = table.Rows.Add();
}
有关详细信息,请参阅以下链接
http://jgvimalan.wordpress.com/2011/02/08/add-rows-to-table-in-ms-word-document-using-c/