Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can u just tell me how to retrieve total number of sheet in a excel file
Posted

C#
   Application _excelApp = new Application();
Workbook workBook = _excelApp.Workbooks.Open("d:/Book1.xls");

int numSheets = workBook.Sheets.Count;
 
Share this answer
 
Comments
Member 10891595 18-Jun-14 4:42am    
pls eleborate this sir
 
Share this answer
 
Comments
Member 10891595 18-Jun-14 5:40am    
pls sir give me the exact solution of my problem
Richard MacCutchan 18-Jun-14 6:37am    
Don't be lazy, go and read the article and try it for yourself.
Member 10891595 18-Jun-14 23:29pm    
dear sir when i m applying ur code in my project i m getting following error pls provide me the exact solution for this

Excel cannot open the file 'Test Input.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.
Richard MacCutchan 19-Jun-14 4:11am    
What do you mean the exact solution? The message explains exactly what is wrong, you need to examine the file to find out why.
I hope this link will help you :-
C# - Retrieve Excel Workbook Sheet Names.[^]

Good luck.
 
Share this answer
 
v2
Comments
Member 10891595 18-Jun-14 4:43am    
sry sir i can not get it is there are any other way for this
Raje_ 18-Jun-14 8:38am    
Pls check solution 2 :
int numSheets = workBook.Sheets.Count;
this line gets the number of sheets.
Raje_ 19-Jun-14 3:43am    
Who has down voted.....LOL!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900