ASP. NET ends the Excel Process

Source: Internet
Author: User

I. There are two methods to solve the operation permission problem:

1. Use a simulated account and add it to the Web. config file.

 
 
  1. <!identity impersonate="true" userName="administrator" password=""/> 

2. In the DCOM component service, grant the ASP. NET Operation permission to the MICROSOFT. EXCEL component. The procedure is as follows:
1) Open the run dialog box of the Start Menu, enter the dcomcnfg command, and click OK. The component service window is displayed.
2) expand computer> my computer> DCOM, and find the Microsoft Excel application node.
3) Right-click-> properties, select the "Security" option, select "Custom" for each of the following three projects, and click the edit button.
4) Click the Add button in the launch permission dialog box to add corresponding users. Note: if it is WIN2000 or XP, add the "machine name/ASPNET" user. Here we use WIN2003 as an example, WIN2003 is used to add a "NETWORK Service" user) and grant the maximum permission to the user.

Ii. ASP. NET end the Excel Process

1. In the previous article, I used ASP to determine the process startup time. NET to end the Excel process, although it seems a bit inappropriate, but I have never encountered any problems, never mistakenly killed other Excel processes.

2. Release the resources of all used Excel objects. Copy a piece of code here:

 
 
  1. Objectmissing=System. Reflection. Missing. Value;
  2. Microsoft. Office. Interop. Excel. ApplicationmyExcel=NewMicrosoft. Office.
    Interop. Excel. ApplicationClass ();
  3. MyExcel. Visible=False;
  4. // Open a new file
  5. Microsoft. Office. Interop. Excel. WorkbooksmyBooks=MyExcel. Workbooks;
  6. Microsoft. Office. Interop. Excel. WorkbookmyBook=MyBooks.
    Open (sourceFile, missing ,...);
  7. Microsoft. Office. Interop. Excel. WorksheetcurSheet=
    (Microsoft. Office. Interop. Excel. Worksheet) myBook. ActiveSheet;
  8.  
  9. Microsoft. Office. Interop. Excel. Rangerans=
    (Microsoft. Office. Interop. Excel. Range) curSheet. Cells;
  10. Microsoft. Office. Interop. Excel. Rangeran=Null;
  11. Microsoft. Office. Interop. Excel. RangeranMerge=Null;
  12. Microsoft. Office. Interop. Excel. RangeranRows=Null;
  13. Microsoft. Office. Interop. Excel. RangeranCells=Null;
  14. For (Inti=0; I<10; I ++)
  15. {
  16. For (Intj=0; J<10; J ++)
  17. {
  18. Ran= (Microsoft. Office. Interop. Excel. Range) rans [I + 1, j + 1];
  19.  
  20. RanRanMerge= Ran. MergeArea;
  21. RanRows=RanMerge. Rows;
  22. IntmergeRows=RanRows. Count;
  23. RanCells=RanMerge. Cells;
  24. IntmergeCells=RanCells. Count;
  25. Response. Write ("<Br/>"+ I +": "+ j +": "+ ran. Text );
  26.  
  27. System. Runtime. InteropServices. Marshal. ReleaseComObject (ranCells );
  28. RanCells=Null;
  29.  
  30. System. Runtime. InteropServices. Marshal. ReleaseComObject (ranRows );
  31. RanRows=Null;
  32.  
  33. System. Runtime. InteropServices. Marshal. ReleaseComObject (ranMerge );
  34. RanMerge=Null;
  35.  
  36. System. Runtime. InteropServices. Marshal. ReleaseComObject (ran );
  37. Ran=Null;
  38. }
  39. }
  40.  
  41. System. Runtime. InteropServices. Marshal. ReleaseComObject (rans );
  42. Rans=Null;
  43.  
  44. System. Runtime. InteropServices. Marshal. ReleaseComObject (curSheet );
  45. CurSheet=Null;
  46.  
  47. MyBook. Close (false, Type. Missing, Type. Missing );
  48. System. Runtime. InteropServices. Marshal. ReleaseComObject (myBook );
  49. MyBook=Null;
  50.  
  51. MyBooks. Close ();
  52. System. Runtime. InteropServices. Marshal. ReleaseComObject (myBooks );
  53. MyBooks=Null;
  54.  
  55. MyExcel. Quit ();
  56. System. Runtime. InteropServices. Marshal. ReleaseComObject (myExcel );
  57. MyExcel=Null;
  58.  
  59. GC. Collect ();
  60. GC. WaitForPendingFinalizers ();

These two problems are summarized for the time being. These solutions come from the Internet. Here I will just summarize them. By the way, I will download some Excel controls I have collected for you:
Http://files.cnblogs.com/lingyun_k/ExcelWriter.rar

This is cracked.
Http://files.cnblogs.com/lingyun_k/Aspose%20Excel%20V2.3.1.1.NET.rar

Another one is ExcelQuicker, which has strong functions. You can find it after searching. However, I think the golden printing King is more convenient than Excel, but does not support WebForm, the above introduces ASP. NET ends the Excel Process

  1. Analysis of Theme functions in ASP. NET development skills
  2. ASP. NET Dynamic Compilation
  3. Analysis on ASP. NET supported by Apache
  4. Introduction to ASP. NET Server standard controls
  5. Analysis on SQL Server Database Backup Recovery in ASP. NET

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.