Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get only those colums in a EXCEL worksheet that have a value

I am programatically reading an Excel file in C#.

When I use Excel.Worksheet.Columns.columns.count, I get a value above 16,000.

But my excel sheet has only 15 columns. How do I get only those columns that have a value?

like image 319
Devdatta Tengshe Avatar asked Dec 28 '25 21:12

Devdatta Tengshe


1 Answers

Here is how I usually do this:

Excel.Application demoApp= new Excel.Application();
demoApp.Workbooks.Open(fileName);
int rowCount = demoApp.ActiveSheet.UsedRange.Rows.Count;
int colCount = demoApp.ActiveSheet.UsedRange.Columns.Count;

so, the key is to use UsedRange, I hope this will help.

like image 64
Issam Ali Avatar answered Dec 30 '25 10:12

Issam Ali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!