Merge cells using EPPlus?

I use the EPPlus library to read / write Excel files: http://epplus.codeplex.com/

I try to just merge some cells when writing a document:

using (ExcelPackage pck = new ExcelPackage()) { //Create the worksheet ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo"); //Format the header for column 1-3 using (ExcelRange rng = ws.Cells["A1:C1"]) { bool merge = rng.Merge; } } 

There's a property called Merge that just returns true or false. I thought it might be a cell merge, but it is not.

Does anyone know how to do this?

+53
c # excel epplus
May 30 '11 at 5:12
source share
3 answers

You should use it as follows:

 ws.Cells["A1:C1"].Merge = true; 

instead:

 using (ExcelRange rng = ws.Cells["A1:C1"]) { bool merge = rng.Merge; } 
+95
May 30 '11 at 5:49
source share

If you want to merge cells dynamically, you can also use:

worksheet.Cells[FromRow, FromColumn, ToRow, ToColumn].Merge = true;

All of these variables are integers.

+43
Sep 02 '14 at 7:02
source share

You can create an extension method:

 public static void Merge(this ExcelRangeBase range) { ExcelCellAddress start = range.Start; ExcelCellAddress end = range.End; range.Worksheet.Cells[start.Row, start.Column, end.Row, end.Column].Merge = true; } 

You can use this as you could with interop:

 range.Merge(); 
+3
Jan 26 '17 at 12:02 on
source share



All Articles