Operation in ASP.NET, Excel often occurs the situation of the background Excel process, and I have searched some information recently.
It is already possible to turn off Excel in the program, the code is as follows:
Excel.Application myexcel; Excel._Workbook MyWb; Excel._worksheet myws = null; Excel.Range myrange = NULL;
String filepath = server.mappath ("// Test ///"); Share.Share myshclass = new share.share (); string strp = filepath myshclass.getcurtimeasid () ".xls"; fileinfo file = new fileInfo STRP);
Try {myexcel = new Excel.Application (); myexcel.visible = false; mywb = myexcel.workbooks.add (true); myws = (Excel._worksheet) Mywb.sheets.add (Type.Missing, Type.Missing, Type .Ssing, type.missing; myws = (Excel._Worksheet) Mywb.sheets [1]; for (int i = 0; i During the process of writing code, the appeal is written according to the appeal method, and the case where Excel is not closed, and then discovered is mainly Due to the two separate assignments, for example, MyRANGE = (Excel.Range) myws.cells [1,1]; myrange = (Excel.Range) Myws.cells [1, 2]; there is a problem with the above writing, and it is changed For (int i = 0; i <= 2; i ) {myrange = (Excel.Range) Myws.cells [1, i];} There will be no problem, although I don't quite understand why, but I will find the problem. Therefore, it is recommended that you use the loop when you operate the Excel object. In general, ASP.NET has many problems with Excel's operation, and I don't know if it will be Close the process of Excel, and you need to change some security settings for the server, Comparison, but use the above method to basically do the normal shutdown Excel, hoping Everyone has help!