2

I want to apply data validation and styling to a column range, but without the header cell. Now I'm doing it in two steps:

  • Apply rules to a column range
  • Clear the header cell

It works, but I have to edit header cells after all other cells. And it looks like a hack, there might be a nicer way.

So, how to select the column without a top cell?

astef
  • 8,575
  • 4
  • 56
  • 95

2 Answers2

2

If you know the number of the last row you want to style, you could use a Range() like this:

worksheet.Range(2, col1, row, col2).Style....;

If not you could get the Cells() from your column range and skip the first row like this:

worksheet.Columns(col1, col2).Cells().Where(c => c.WorksheetRow().RowNumber() != 1).Style....;
Raidri
  • 17,258
  • 9
  • 62
  • 65
0

If myRange is your column original range (including header row), how about:

var rangeWithoutHeader = worksheet.Range(myRange.FirstCell().CellBelow(), myRange.LastCell());
Seb Wills
  • 834
  • 9
  • 11