Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge cells using EPPlus?

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

I'm trying to simply 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 named Merge that simply returns true or false. I thought maybe that would Merge the cells, but it doesn't.

Anyone know how to do this?

like image 273
Steven Avatar asked May 30 '11 05:05

Steven


People also ask

How do I merge cells in EPPlus?

If you want to merge cells dynamically, you can also use: worksheet. Cells[FromRow, FromColumn, ToRow, ToColumn].

How to merge cells in devexpress?

Enabling Cell MergingAt design time, access the View's properties, then expand GridView. OptionsView and enable the GridOptionsView. AllowCellMerge option.

How to merge cells in excel open xml c#?

You can use the MergeCells and MergeCell classes to create the merged cells you require. The MergeCells class is the collection of merge cells ( <mergeCells count="3"> in your XML) and the MergeCell class represents each individual set of merged cells ( <mergeCell ref="xx:xx" /> in your XML).


2 Answers

You have to use it like this:

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

instead of:

using (ExcelRange rng = ws.Cells["A1:C1"]) {     bool merge = rng.Merge; } 
like image 93
Carles Company Avatar answered Oct 02 '22 09:10

Carles Company


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

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

All these variables are integers.

like image 25
mayank Avatar answered Oct 02 '22 10:10

mayank