Creating a range for a column without first cell

Jul 21, 2011 at 2:55 PM

I need to create a range that covers the WHOLE column (e.g., worksheet.Column(5)), with the exception of the very first cell, since it will contain column title, not a value that will have to be validated later. Possible?

I can do something like this:

var range = worksheet.Range(2, column, worksheet.LastCell().Address.RowNumber, column);

But it feels a little ugly. Is there a more elegant way to achieve this? Perhaps you could expose MaxNumberOfRows found in internal class ClosedXML.Excel.XLWorksheet, so that I wouldn't have such an unsightly workaround to get to it? :) 

Jul 21, 2011 at 3:12 PM

I'll expose those constants.

Once you have that I think a more elegant way would be:

var columnSegment = worksheet.Column(column).Column(2, MaxNumberOfRows);

This is available now, except for the constant of course.

Jul 21, 2011 at 3:17 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jul 21, 2011 at 3:18 PM

Well.. On the other hand, is it really a good idea to create huge ranges like E2:E1048576? My app is running out of memory on second creation of such a range.

Jul 21, 2011 at 3:20 PM

I'll check that too...

Jul 24, 2011 at 5:18 AM
Edited Jul 24, 2011 at 5:19 AM

Actually, now that I play with it I think it's better to leave as it is and you can do:

var columnSegment = ws.Column(1).Column(2, ws.RowCount());

It's very clean. The problem I'm having is that I don't know where to put the constant for you to access it.

btw, I'm not getting the memory problem (must have been fixed along with the rest).