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