- Welcome, Guest. Please Login or Register
MindFusion  
  Version 2 of our Xamarin Calendar component adds Resource view and support for Universal Windows Platform. Now beta testing spreadsheet component for Java Swing. We have released our Java Swing Pack.  
  HomeHelpSearchLoginRegister   
     
     
   
 
Page Index Toggle Pages: 1 Send Topic Print  
Check the number of rows in a worksheet
Read 726 times

antoan.73   Offline
YaBB Newbies
*
Posts: 1
I Love MindFusion!


   
     
 
Check the number of rows in a worksheet
Aug 9th, 2016 at 7:24am
 
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
 
 
 
IP Logged    
 
     

Meppy   Offline
YaBB Moderator
*****
Posts: 1761
Gender: male
MindFusion support


   
     
 
Re: Check the number of rows in a worksheet
Reply #1 - Aug 9th, 2016 at 8:43am
 
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:
// 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
 
 
 
IP Logged    
 
     
Page Index Toggle Pages: 1 Send Topic Print