From: https://blog.csdn.net/qq_38974638/article/details/109296332
1 橫向合併
實現程式碼:
using Aspose.Words.Tables
Document doc=new Document("test.doc");
DocumentBuilder builder =new DocumentBuiler();
int tableIndex=0;
//移動至第一行第一列
builder.MoveToCell(tableIndex,0,0,0);
builder.CellFormat.HorizontalMerge = CellMerge.First;//合併的第一個單元格
//移動至第一行第二列
builder.MoveToCell(tableIndex,0,1,0);
builder.CellFormat.HorizontalMerge = CellMerge.Previous;//被合併的單元格
最終效果圖:
2 縱向合併
實現程式碼:
using Aspose.Words.Tables
Document doc=new Document("test.doc");
DocumentBuilder builder =new DocumentBuiler();
int tableIndex=0;
//移動至第一行第一列
builder.MoveToCell(tableIndex,0,0,0);
builder.CellFormat.VerticalMerge = CellMerge.First;//合併的第一個單元格
//移動至第二行第一列
builder.MoveToCell(tableIndex,1,0,0);
builder.CellFormat.VerticalMerge = CellMerge.Previous;//被合併的單元格
最終效果圖:
----------------------------------------------------------------------------------------
From: https://blog.csdn.net/u011511086/article/details/136565515
if (result.total==0) //如果沒記錄
{
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.First;//水平合併單元格
builder.Write("暫無資料");
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;//水平合併單元格
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;//水平合併單元格
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;//水平合併單元格
builder.EndRow(); /* 結束一行 */
}