Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Check the number of rows in a worksheet (Read 3370 times)
antoan.73
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 1
Joined: Aug 9th, 2016
Check the number of rows in a worksheet
Aug 9th, 2016 at 6:24am
Print Post  
Hi, is there a simple way to get the number of rows (and columns) in a worksheet that actually contain data? I tried Worksheet.Rows.Count, but it return the total number of rows.

Cheers
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Check the number of rows in a worksheet
Reply #1 - Aug 9th, 2016 at 7:43am
Print Post  
Hi,

You can enumerate the Worksheet.Cells collection - it should iterate only over the cells containing data. The following code snippet illustrates how to do this:

Code
Select All
// Load the workbook from a file
Workbook workbook = new Workbook();
ExcelImporter importer = new ExcelImporter();
importer.Import(@"c:\Users\Meppy\Hearthstone.xlsx", workbook);

// Obtain the first worksheet
var worksheet = workbook.Worksheets[0];

// Iterate over the worksheet cells and collect the max row and column
int column = worksheet.Cells.Max(cell => cell.Column) + 1;
int row = worksheet.Cells.Max(cell => cell.Row) + 1;

// Display the result
Debug.WriteLine("columns: {0}, rows: {1}", column, row); 


Let me know if this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint