日期:2014-05-17  浏览次数:20396 次

ASP.NET 向word 插入多个table 怎么在table 结尾换行后再插入一个table
求助一下,我现在遇到一个asp.net 生成WORD 的问题,我向WORD 插入多个 table ,通过
Word.Table newTable1 = WordDoc.Tables.Add(WordApp.Selection.Range, Row, Colum, ref Nothing, ref Nothing);
来插入,但是当插入第二个表格的时候 没有在第一个表格的结尾出 换行 从新插入,而是永远在第一个表格的第一个单元格里面插入。
求助一下,我想循环向WORD中插入多个表格,及每个表格都是独立的 中间都空一行,谢谢
下面是我的代码:
for (int i = 0; i < 3; i++)
  {
  dsath = T3_ath.GetList("F_DegationId='" + dsDele.Tables[0].Rows[0]["F_ID"].ToString() + "'");
  Row = dsath.Tables[0].Rows.Count + 1;
  Colum = dsath.Tables[0].Columns.Count;


  //移动焦点并换行
  object count = Row;
  object WdLine = Word.WdUnits.wdLine;//换一行;
  WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
   
  //文档中创建表格
  Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, Row, Colum, ref Nothing, ref Nothing);
  for (int j = 0; j < dsath.Tables[0].Columns.Count; j++)
  {
  newTable.Cell(0, j).Range.Text = dsath.Tables[0].Columns[j].Caption;
  }  
}

------解决方案--------------------
加个这个方法
//跳转到文档末尾
public void GoToTheEnd()
{
object missing = System.Reflection.Missing.Value;
object unit;
unit = Word.WdUnits.wdStory;
oWordApplic.Selection.EndKey(ref unit, ref missing);
}
------解决方案--------------------
Selection.TypeParagraph

------解决方案--------------------
我想和excel大致相似的
newTable.Cell(0, j)这里rowindex是0好像不对
应该比如说声明一个h,然后
newTable.Cell(h++,j)。。。