C# 在EPPLUS中使用合并相同的值

C# 在EPPLUS中使用合并相同的值,c#,C#,在使用EPPLUS生成EXCEL时,当我的第一列值相同时,我需要动态合并。我的列数据在员工加入和终止时更改。所以,我想知道如何动态合并,如果列是相同的值,我需要突出显示每个总行只有背景颜色 这是我第一次使用EPPLUS。我不知道如何在此页面中附加示例excel文件 我在此链接中附加了示例Excel文件 请帮我解决这个问题 您可以按照以下示例进行合并: using (ExcelPackage excel = new ExcelPackage(new FileInfo(filePath))) {

在使用EPPLUS生成EXCEL时,当我的第一列值相同时,我需要动态合并。我的列数据在员工加入和终止时更改。所以,我想知道如何动态合并,如果列是相同的值,我需要突出显示每个总行只有背景颜色

这是我第一次使用EPPLUS。我不知道如何在此页面中附加示例excel文件

我在此链接中附加了示例Excel文件


请帮我解决这个问题

您可以按照以下示例进行合并:

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
}
使用(ExcelPackage excel=new ExcelPackage(new FileInfo(filePath)))
{
excel工作表=excel.工作簿.Worksheets[1];

对于(int currentRow=worksheet.Dimension.Start.Row;currentRow),我的要求非常相似,但我想检查相同值的列