如何在foreach循环中通过Excel上的第一行?

Cri*_*and 0 c#

我有阅读Excell记录的代码:

public IEnumerable<FillinEntity> Map(IEnumerable<ExcelRow> excelRows)
            {

                List<FillinEntity> fillinEntities = new List<FillinEntity>();

                foreach (ExcelRow row in excelRows)
                {

                    FillinEntity excell = new FillinEntity();
                    excell.SerialNumber = Convert.ToString(row.Cells[0]);
                    excell.PalletNumber = Convert.ToString(row.Cells[1]);
                    excell.Location = Convert.ToString(row.Cells[2]);
                    excell.CreatedBy = Convert.ToString(row.Cells[3]);

                    fillinEntities.Add(excell);

                }

                return fillinEntities;
            }
Run Code Online (Sandbox Code Playgroud)

我有这样的记录:它成功插入

R03091294   2    2  FGROOM  RYAN
Run Code Online (Sandbox Code Playgroud)

我的问题:我在excell表上添加列标题.

Serial Number    Pallet      Location   CreatedBy -----> i need to by pass column header.
R03091294   2    2         FGROOM     RYAN
Run Code Online (Sandbox Code Playgroud)

谢谢你的问候

Cod*_*uth 5

你总是可以跳过它:

foreach (ExcelRow row in excelRows.Cast<ExcelRow>().Skip(1))
Run Code Online (Sandbox Code Playgroud)

Skip().

注意:我用过Cast<ExcelRow>()以防你的枚举excelRows无法解析ExcelRow.