Close the current process during Excel operations

Source: Internet
Author: User

When operating Excel, you can see that one way is to kill all the "Excel" processes. In this way, if a document is opened, it will be closed without prompting whether to save it. the user will go crazy, the following method can only kill the current process

 

Microsoft. Office. InterOP. Excel. Application m_xlapp =   New Microsoft. Office. InterOP. Excel. Application ();
Int M_k = M_xlapp.hwnd;

//Operation

Killprocess (m_k );//Close Process

// Closing Method
[Dllimport ( " User32.dll " , Charset = Charset. Auto)]
Public   Static   Extern   Int Getwindowthreadprocessid (intptr hwnd, Out   Int ID );
///   <Summary>
/// Kill Process
///   </Summary>
///   <Param name = "ID"> </param>
Private   Static   Void Killprocess ( Int ID)
{
Intptr t =   New Intptr (ID );
Int K =   0 ;
Getwindowthreadprocessid (t, Out K ); // Obtain the unique identifier K of the process.
If (K ! =   0 )
{
System. Diagnostics. PROCESS p = System. Diagnostics. process. getprocpolicyid (k ); // Get reference to process K
P. Kill (); // Disable process K
}

 

In this way, it can be operated, and it is even more useful in loop operations. In the past, when I export Sina Blog to word, I killed all input methods. The method is easy to use, but it is not reasonable, it feels good to use the above example.

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.