How to get only those columns on the EXCEL worksheet that matter

I programmatically read 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 to get only those columns that matter ?

+3
source share
2 answers

This is how I usually do it:

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 should use UsedRange , I hope this helps.

+4
source

When you try to automate Excel, you can first figure out how to do what you want in Excel, and then figure out a way to do this using the automation API.

, "" Excel, , , . "XFD1" . 16 000.

, , End, " ", Left Arrow, 15 "O" "O1".

API # " "? Range.End. :

VBA End:

Excel , VBA - , #.

Excel, , , API !

0

All Articles