Recently, the project needs to operate Excel in ASP. NET. There is no problem with encoding, and some problems have been encountered in environment settings. After several days of study, I finally got it done.
Summary:
Environment Settings:
1. Excel must be installed on the server.
I started to dream about using DLL for release. Some forums said yes. After several days of hard work, I confirmed that all these are yy.
2. DCOM permission settings.
There are a lot of detailed information on the Internet and screenshots are also provided.
3. The Sky knows what it is.
In an environment, it is clear that the setting is successful. if the machine is switched, the setting fails, and the excel.exe fails.
Programming considerations;
1. It is necessary to release the COM object. Because the COM object is not hosted Code .
Try
{
If(O! = Null)
Marshal. releasecomobject (O );
}
Finally
{
O= Null;
}
2. Save and close the Excel file. If (WB ! = Null )
{
WB. Saved= True;
WB. Close (False, Type. Missing, type. Missing );
}
TIPS:
It is best not to use com Excel operations, MS is not recommended, and easy to error. If you only want to read and write Excel files, use oledb directly.
Fatal problem:
When an interactive query occurs in Excel, ASP. NET will wait for the request to die.