MFC uses App.Quit (); Cannot exit Excel table resolution

Source: Internet
Author: User

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

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.