Live Chat Icon For mobile
Live Chat Icon

How to get the count of rows in a Excel file

Platform: ASP.NET| Category: Miscellaneous

Add reference -> COM tab ->Microsoft Excel 11.0 Object Library


<asp:Label id='Label1' runat='server'></asp:Label>

VB.NET


Dim excelApp As New Microsoft.Office.Interop.Excel.Application
excelApp.Workbooks.Open(Server.MapPath('excel1.xls'))
Label1.Text = excelApp.ActiveSheet.Usedrange.count.ToString
excelApp.Workbooks.Close()

C#


Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
excelApp.Workbooks.Open ( Server.MapPath ('excel1.xls'), Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing );
Microsoft.Office.Interop.Excel.Worksheet wks;
wks =(Microsoft.Office.Interop.Excel.Worksheet)excelApp.ActiveSheet;
Label1.Text =wks.UsedRange.Count.ToString();
excelApp.Workbooks.Close();

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.