【java】Aspose.Words 合并单元格2种情况(横向合并,纵向合并)
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(); /* 结束一行 */
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET10 - 预览版1新功能体验(一)