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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With