Click here to Skip to main content
15,920,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
string filepath = Server.MapPath(@"~/MSME_Admin/CMA_Data/Book1.xls");
// To Open existing Excel From Folder
Application ExcelObj = new Excel.Application();
Workbook WBook = ExcelObj.Workbooks.Add(filepath);
Worksheet WSheet = (Excel.Worksheet)WBook.Sheets.get_Item(1);
Range range = null;

What I have tried:

i am getting this error, why are coming this error i din't understand. Please Give some solution.
Posted
Updated 14-Jun-18 5:42am

Error 80040154 means Office is not installed on the server.

You should also read the following Microsoft knowledgebase article:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.


Since you're trying to read an old-style Excel document (.xls), you'll need to use NPOI:
GitHub - tonyqus/npoi: a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.[^]

For new-style documents (.xlsx), there are several other alternatives:


None of these use Interop, and none of them require you to install and license Office on your server.
 
Share this answer
 
Automating Excel is not supported under asp.net, you'll need to use some other way to manipulate your Excel files such as EPPlus, XML SDK, Aspose, Excel ODBC Driver etc.
 
Share this answer
 
v2
Error 0x80040154 is "Class not registered".

To know which class is not registered, we would have to know the CLSID from your error message.

Because it occurs when trying to use Excel Interop, I guess that Excel is not (properly) installed on your system. Then the solution is to execute the Excel / Office setup to (re-)install / repair.
 
Share this answer
 
Comments
Dave Kreskowiak 14-Jun-18 12:23pm    
There's a much bigger problem than just installing Office. Office cannot be used via Interop in a non-user-interactive session, i.e. Windows Services and especially not ASP.NET applications.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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