-1

I need to merge the dynamically when my first column values are same in EXCEL Generation using EPPLUS. My column data was change when employees joining and termination. So, I want to konw How to dynamically merge if the columns are same values and I need to Highlight the each Total row only with backgroud color.

Am a beginner this was my first time I am using the EPPLUS. I don't know how to attach the sample excel file in this page.

I attached sample Excel file in this link https://www.c-sharpcorner.com/forums/merge-the-same-values-using-in-epplus.

Please help me to get resolved.

Nova
  • 23
  • 3

1 Answers1

1

You can follow this example to merge:

using (ExcelPackage excel = new ExcelPackage(new FileInfo(filePath)))
{
    ExcelWorksheet worksheet = excel.Workbook.Worksheets[1];

    for (int currentRow = worksheet.Dimension.Start.Row; currentRow <= worksheet.Dimension.End.Row; currentRow++)
    {
        string firstCellValue = worksheet.Cells[currentRow, 1].Value == null || worksheet.Cells[currentRow, 1].Value.ToString() == "" ? null : worksheet.Cells[currentRow, 1].Value.ToString();
        string secondCellValue = worksheet.Cells[currentRow, 2].Value == null || worksheet.Cells[currentRow, 2].Value.ToString() == "" ? null : worksheet.Cells[currentRow, 2].Value.ToString();

        if (firstCellValue == secondCellValue)
        {
            worksheet.Cells[currentRow, 1, currentRow, 2].Merge = true;
        }
    }

    // Save file
}
EzLo
  • 13,780
  • 10
  • 33
  • 38