How to generate Excel form EPPluse which has group column header

397 Views Asked by At

I want to generate excel sheet from EPPluse which has group column header like below picture.Then How to build DataTable which handle this situation. please help me to get it done easily.

enter image description here

Thanks in advance

1

There are 1 best solutions below

0
On

You want to use the Merge property on the ExcelRange object.

Here's an example:

using (var pck = new ExcelPackage(new FileInfo(@"c:\temp\Book1.xlsx")))
{
    var ws = pck.Workbook.Worksheets["Sheet1"] ?? pck.Workbook.Worksheets.Add("Sheet1");

    var rng = ws.Cells["BO1:BQ1"];
    rng.Merge = true;
    rng.Value = "Answer for Att 3";

    pck.Save();
}

You can use this code to write your group headers, then use ExcelRange's LoadFromDataTable() method to write your DataTable directly to the worksheet starting from cell A2