c# - Load Excel process and close the entire process when closing a document -
In my C # application, I can open a new Excel procedure by clicking on a button again, wait for this input useless Does and loads a new Excel file. I have to fulfill it because I need all the macros and loads of equipment before loading my documents (otherwise, there is a rendering bug).
The process ID is saved in a var, and when I click again on that button, with PID, if the process already exists, then there is a focus in the process, otherwise, A new process is created:
Process processXcel = faucet; If (pId_m.HasValue) {try {processExcel = Process.GetProcessById (pId_m.Value); } Hold (exception before) {Log.MonitoringLogger.Error ("unable to find PID:" + pId_m, ex); }} If (ProcessEXell! = Null & amp; amp; amp; amp; amp; amp; Processes Xcel. HasExited == Wrong)) {Automation Element Element = Automation Element. Froghandle (processExcel.MainWindowHandle); If (element! = Zero) {element.SetFocus (); }} And {ProcessStartInfo info = new ProcessStartInfo (); Info.FileName = "Excel.exe"; Info.Arguments = "/ e"; ProcessExcel_l = Process Start (info); PId_m = processExcel_l.Id; ProcessExcel_l.WaitForInputIdle (); ProcessExcel_l.StartInfo = New ProcessStartInfo (Path); ProcessExcel_l.Start (); } The problem is the following: When I close the Excel document window (and not the Excel window), and I click on the button, the focus is set to the Excel process, but without Any document ... This behavior is rational but is not working for what I want ...
I have seen a software that loads a new process and a new document, But when clicking on the Close Close button Areas are, was out of the whole process ... is that how again can be generated?
Edit : OK, In the end, instead of setting the focus on this process, I have launched a file on this process (which is the focus Is already open if it does focus).
It is not what I really wanted to do, but it resolves my problem ...
I would recommend using the Excel COM model instead of running the process manually. You can subscribe to worksheet events and close the application.
These MSDN documents can be useful:
Comments
Post a Comment