Skip to content
This repository has been archived by the owner on Feb 20, 2021. It is now read-only.

Settting header row index in "ToList" method #28

Open
JPiris88 opened this issue Jan 21, 2020 · 1 comment
Open

Settting header row index in "ToList" method #28

JPiris88 opened this issue Jan 21, 2020 · 1 comment
Assignees

Comments

@JPiris88
Copy link

Hi.

I think it'd be a good idea to have a "headerRowIndex" parameter in "ToList" extension method to start reading the rows from a certain row index. "CheckAndThrowIfDuplicatedColumnsFound" and "CheckHeadersAndThrow" methods have this parameter and the validation works well.

@JPiris88
Copy link
Author

This can be a possible solution:

// The header isn't on the first row but on the fifth
int headerRowIndex = 5;

// Create a temp worksheet to copy the rows from the original one to the first row
var rowsWorksheet = package.AddWorksheet("Rows");

worksheet.Cells[
        FromRow: headerRowIndex,
        FromCol: 1,
        ToRow: worksheet.Dimension.End.Row,
        ToCol: worksheet.Dimension.End.Column
    ]
    .Copy(rowsWorksheet.Cells[
        FromRow: 1,
        FromCol: 1,
        ToRow: worksheet.Dimension.End.Row - headerRowIndex,
        ToCol: worksheet.Dimension.End.Column
    ]);

var rows = rowsWorksheet.ToList<MyClass>();

@eraydin eraydin self-assigned this Feb 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants