你可以引用类库Spire.XLS.dll来实现
1.合并单元格
//创建工作簿,加载文档
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
//获取单元格,合并
workbook.Worksheets[0].Rows[0].Merge();
workbook.Worksheets[0].Range["A3:B5"].Merge();
//保存文档
workbook.SaveToFile("Merge.xlsx");
合并效果:
2.拆分单元格
//创建工作簿,加载文档
Workbook workbook = new Workbook();
workbook.LoadFromFile("Merge.xlsx");
//获取单元格范围,拆分
workbook.Worksheets[0].Rows[0].UnMerge();
workbook.Worksheets[0].Range["A3:B5"].UnMerge();
//保存文档
workbook.SaveToFile("UnMerge.xlsx");
拆分效果: