// 给 Word 文档中的数据表插入空行(注:表中已有一行空行~) #region InsertEmptyRowsToTable /// <summary> /// 给 Word 文档中的数据表插入空行(注:表中已有一行空行~) /// </summary> /// <param name="selection"></param> /// <param name="table"> word 文档中的表格 </param> /// <param name="docRowStart"> word 表格的起始行 </param> /// <param name="rowCount">要插入的空行数目</param> /// <param name="logInfo"> 日志内容 </param> /// <returns></returns> public static bool InsertEmptyRowsToTable(ref Word.Selection selection, ref Word.Table table, int docRowStart, int docColStart, int rowCount, out string logInfo) { bool res = true; try { // 2012-01-10 Update if (rowCount > 1) { table.Cell(docRowStart, docColStart).Select(); selection.InsertRowsBelow(rowCount - 1); logInfo = "插入空行成功!"; } else { res = false; logInfo = "无对应的数据记录!"; } } catch (Exception ex) { JCMsg.ShowErrorOK(ex.GetType().ToString() + "\n" + ex.Message); res = false; logInfo = "插入空行失败!"; } return(res); }
public void InsertRowsInTable(int indTable, int nCount) { if (nCount <= 0) { return; } if (m_pApp != null) { if (m_pDoc == null) { m_pDoc = m_pApp.ActiveDocument; } if (m_pDoc == null) { return; } MSWord.Tables tables = m_pDoc.Tables; if (tables.Count == 0) { return; } m_pTable = tables[indTable]; if (m_pTable == null) { return; } m_pTable.Select(); MSWord.Selection pSel = m_pApp.Selection; pSel.InsertRowsBelow(nCount); m_pDoc.Select(); m_pSelection = m_pApp.Selection; if (m_pSelection == null) { return; } m_pSelection.Collapse(0); } }