单元格"/>
npoi获取合并单元格
//合并单元格
InitializeWorkbook();
ISheet
sheet = hssfworkbook.CreateSheet("new sheet");
IRow row =
sheet.CreateRow(0);
row.HeightInPoints = 30;
ICell cell
= row.CreateCell(0);
//set the
title of the sheet
cell.SetCellValue("Sales Report");
ICellStyle
style = hssfworkbook.CreateCellStyle();
style.Alignment =
NPOI.SS.UserModel.HorizontalAlignment.Center;
//create a
font style
IFont font
= hssfworkbook.CreateFont();
font.FontHeight = 20 * 20;
style.SetFont(font);
cell.CellStyle = style;
//merged
cells on single row
//ATTENTION: don't use Region class, which is obsolete
sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0,
5));//合并单元格,从0,0开始到0,5
//merged
cells on mutiple rows
CellRangeAddress region = new CellRangeAddress(2, 4, 2,
4);
sheet.AddMergedRegion(region);
//set
enclosed border for the merged region
((HSSFSheet)sheet).SetEnclosedBorderOfRegion(region,
NPOI.SS.UserModel.BorderStyle.Dotted,
NPOI.HSSF.Util.HSSFColor.Red.Index);
WriteToFile();
更多推荐
npoi获取合并单元格
发布评论