/// <summary> /// 合并 /// </summary> /// <param name="builder"></param> /// <param name="table"></param> /// <param name="mcell"></param> public static void MergeCell(Aspose.Words.DocumentBuilder builder, Table table, IList <MCell> mcell) { try { var rCount = table.Rows.Count; var cCount = table.Rows[0].Cells.Count; for (int i = 0; i < mcell.Count; i++) { var m = mcell[i]; if (m.IsColumn) { //某一列进行合并 //到达的行大于总行数、或者起始的某一列所以大于总列数 if (m.toR2C > rCount || cCount < m.C2RIndex) { continue; } //开始位置,起始行的开始列 Cell sCell = table.Rows[m.fromR2C].Cells[m.C2RIndex]; //结束位置,结束行的开始列 Cell eCell = table.Rows[m.toR2C].Cells[m.C2RIndex]; builder.AAMergeCells(sCell, eCell); } else { //某一行进行合并 //到达列大于总列数或者起始的某一行大于总行数 if (m.toR2C > cCount || rCount < m.C2RIndex) { continue; } Cell sCell = table.Rows[m.C2RIndex].Cells[m.fromR2C]; Cell eCell = table.Rows[m.C2RIndex].Cells[m.toR2C]; builder.AAMergeCells(sCell, eCell); } } } catch (Exception ex) { } }