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?
If you want to merge cells dynamically, you can also use: worksheet. Cells[FromRow, FromColumn, ToRow, ToColumn].
Enabling Cell MergingAt design time, access the View's properties, then expand GridView. OptionsView and enable the GridOptionsView. AllowCellMerge option.
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).
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; }
If you want to merge cells dynamically, you can also use:
worksheet.Cells[FromRow, FromColumn, ToRow, ToColumn].Merge = true;
All these variables are integers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With