在写入时跳过 excel 传播 sheet 的前两行

Skipping the first two rows of an excel spread sheet while writing to it

我有这种方法可以将数据写入我的 excel 电子表格。我想跳过前两行 在写出数据之前。前两行包含 headers。我怎样才能跳过前两行?

            public ExcelWorksheet WriteToExcelWorksheet(ExcelPackage package, IEnumerable<IEnumerable<string>> data)
            {
                var rows = data.ToList();
                var ws = package.Workbook.Worksheets[0];

                for (var r = 0; r < rows.Count; r++)
                {
                    var row = rows[r].ToList();
                    for (var c = 0; c < row.Count; c++)
                    {
                        if (!string.IsNullOrWhiteSpace(row[c]))
                        {
                            if (decimal.TryParse(row[c], out var d))
                            {
                                ws.Cells[r + 1, c + 1].Value = d;
                            }
                            else
                            {
                                ws.Cells[r + 1, c + 1].Value = row[c];
                            }
                        }
                    }
                }

                return ws;
            }

只需相应地开始写行:)

例如在这一行中:

ws.Cells[r + 1, c + 1].Value = d;

制作

ws.Cells[r + 3, c + 1].Value = d;

拥有:

public ExcelWorksheet WriteToExcelWorksheet(ExcelPackage package, IEnumerable<IEnumerable<string>> data)
{
    var rows = data.ToList();
    var ws = package.Workbook.Worksheets[0];

    for (var r = 0; r < rows.Count; r++)
    {
        var row = rows[r].ToList();
        for (var c = 0; c < row.Count; c++)
        {
            if (!string.IsNullOrWhiteSpace(row[c]))
            {
                if (decimal.TryParse(row[c], out var d))
                {
                    ws.Cells[r + 3, c + 1].Value = d;
                }
                else
                {
                    ws.Cells[r + 3, c + 1].Value = row[c];
                }
            }
        }
    }

    return ws;
}