1 Description of the phenomenon
if (!appexcel.createdispatch ("Excel.Application")) {return false;} Wbsbooks.attachdispatch (Appexcel.get_workbooks ()); Lpdisp = wbsbooks.open (M_csXlsPath,covOption, covOption, covOption, covOption, covOption, covOption, covOption, Covoption, covoption, covoption, covoption, covoption, covoption, covoption); Wbbook.attachdispatch (Lpdisp); Lpdisp = wbbook.get_activesheet (); Wssheet.attachdispatch (LPDISP); Rangebasiccells.attachdispatch (Wssheet.get_cells ()); Rangeusedcells.attachdispatch (WsSheet.get_UsedRange ()); Rangetempcells.attachdispatch (Rangeusedcells.get_columns ()); Lmaxcolnum = rangetempcells.get_count (); Rangetempcells.attachdispatch (Rangeusedcells.get_rows ()); Lmaxrownum = rangetempcells.get_count (); Lstartcol = rangeusedcells.get_column (); Lstartrow = rangeusedcells.get_row (); Rangeusedcells.releasedispatch (); Rangetempcells.releasedispatch (); GetinfofromexC (Rangebasiccells, lmaxrownum); Rangebasiccells.releasedispatch (); Wssheet.releasedispatch (); Wbbook.releasedispatch (); Wbsbooks.close (); Wbsbooks.releasedispatch ();//***** Mark 1******appexcel.quit (); Appexcel.releasedispatch ();
In the above code, the line of code that originally commented "//***** tag 1******" does not exist, and the Excel process does not end in the background after executing the code. When this line of code is added, the Excel process ends in the background. The reason is that Wbsbooks is not released and Appexcel cannot exit.
2 workaround for this type of problem
1) See if the variables associated with EXECL are all releasedispatch.
2) See if the variables associated with EXECL are in the correct order when they are closed and released. For example, use Close () first, and then use ReleaseDispatch.
This workaround is summarized in [VC Excel Quit cannot close Excel process, nasty AH!!!!! ] (http://bbs.csdn.net/topics/390039312?page=1#post-395362721)
MFC uses App.Quit (); Cannot exit Excel table resolution