In this
post we’ll see how to merge the two or more cell with each other while creating
the excel sheet using NPOI.
Mentioned
below is code to merge multiple cells, in this example we are merging first
cell to fifth cell of first row (you can adjust row or cell range by passing particular
parameters in CellRangeAddress).
//Created new Workbook
var hwb = new NPOI.HSSF.UserModel.HSSFWorkbook();
//Create worksheet with name.
var sheet = hwb.CreateSheet("new sheet");
//Create row and cell.
var row = sheet.CreateRow(0);
var cell = row.CreateCell(0); ;
//Set text inside cell
cell.SetCellValue("This is Merged cell");
cell.CellStyle.WrapText = true;
//define cell range address
// parameters: -> first row
to last and first cell to last cell
var cra = new NPOI.SS.Util.CellRangeAddress(0, 0, 0, 4);
//Add merged region to sheet.
sheet.AddMergedRegion(cra);
|
Hope
this solution helps you J
Very helpful..Thanks.. :)
ReplyDeleteCan't copy your code directly from page. I'm sad:(
ReplyDeletethank you :)
ReplyDeletevar cra = NPOI.SS.Util.CellRangeAddress(0, 0, 0, 4); gives error "CellRangeAddress cannot be used like method"
ReplyDelete