我也有和你同样的问题
这个方法能解决:SetEnclosedBorderOfRegion()
//merged cells on mutiple rows
CellRangeAddress region = new CellRangeAddress(2, 4, 0, 0);
sheet.AddMergedRegion(region);
//set enclosed border for the merged region
((HSSFSheet)sheet).SetEnclosedBorderOfRegion(region, BorderStyle.DOTTED, NPOI.HSSF.Util.HSSFColor.RED.index);
谢谢,有用。不过我用的最新2.15版本的,需要调用的dll不一样,需要略微调整
这里是我的部门代码:
headerRow.CreateCell(0).SetCellValue("出差人及部门");
//sheet.AddMergedRegion(new CellRangeAddress(2, 2, 0, 1));
CellRangeAddress region21 = new CellRangeAddress(2, 2, 0, 1);
sheet.AddMergedRegion(region21);
((HSSFSheet)sheet).SetEnclosedBorderOfRegion(region21, CellBorderType.THIN, NPOI.HSSF.Util.HSSFColor.BLACK.index);
headerRow.GetCell(0).CellStyle = borderStyle;