Qt and MS Excel
Hello everyone,
I’m writing an application in Qt that manipulates some Excel (.xls) files.
I could get it working and the instrunctions are executed succesfully. But I’m experiencing a problem when closing the application.
At the end of the instructions I call:
- workbook->dynamicCall("Close (Boolean)", false);
- excel->dynamicCall("Quit (void)");
but when I check the Windows Task Manager (CTRL+ALT+DEL) after executing the code I can still see the “EXCEL.exe” process at the process tab. Each time I run the instructions a new “EXCEL.exe” process appears.
Can someone please help me to solve this problem?
Thanks very much.
Leo
6 replies
Hello,
Yes, I’m using ActiveQt.
I’m posting my code below. The code is “silly” and probably could be better wiritten, but it performs the task I need. I’d just need to solve that problem when closing the Excel application.
- {
- QAxObject* excel = new QAxObject( "Excel.Application", 0 );
- QAxObject* workbooks = excel->querySubObject( "Workbooks" );
- QAxObject* workbook = workbooks->querySubObject( "Open(const QString&)", "C:\\Users\\LocalDev\\teste.xls" );
- QAxObject* sheets = workbook->querySubObject( "Worksheets" );
- sheets->dynamicCall("Add()");
- QAxObject* sheet = sheets->querySubObject( "Item( int )", 1 );
- sheet->setProperty("Name","Nova Planilha");
- QAxObject * range = sheet->querySubObject("Cells( int, int)",1,1);
- QAxObject * shapes = sheet->querySubObject("Shapes");
- shapes->dynamicCall("AddPicture( QString&, bool, bool, double, double, double, double","C:\\Users\\LocalDev\\Pictures\\cvrd1.png",true,true,100,100,70,70);
- excel->setProperty("DisplayAlerts", false);
- excel->dynamicCall("Save()");
- //workbook->dynamicCall("Close()");
- //excel->dynamicCall("Quit()");
- workbook->dynamicCall("Close (Boolean)", true);
- excel->dynamicCall("Quit (void)");
- delete shapes;
- delete range;
- delete sheet;
- delete sheets;
- delete workbook;
- delete workbooks;
- delete excel;
- }
Thanks once again.
Leo
I did run into hanging Excel Process when I had a similar code.
On Windows 7 Pro. with Office 2003 I don’t have this problem as long as I follow the order
Save(), Close(),Quit(),Delete()
just the same way as you do in your code.
I was once testing the Office 2010 and I remember I had to use SaveCopyAs
- if(Office2010)
- xlWBWholesale->dynamicCall("SaveCopyAs(const QString&)",getWholesalepath());
- else
- xlWBWholesale->dynamicCall("Save()");
- xlWBWholesale->dynamicCall("Close()");
Though I can’t remember with certainty if that solved the issue you’re talking about.
Hi Leo
In this forum has already discussed Qt and Excel here [developer.qt.nokia.com].
I am using the following method:
- wbooks->dynamicCall("Close()");
- excel->dynamicCall("Quit()");
- delete excel;
Has anyone found a solution to this problem? I have the same problem, the “EXCEL.EXE” process remains in my Task Manager list of running processes after I call Close() and Quit() and delete everything. If I then externally (from my app) open the Excel file that I created, it opens “blank” (like corrupt, not fully drawn), then close Excel, then the process appears to properly close and when I open the file externally again, it is fine. I’d show a snippet of code but its pretty much the same as the snippet posted here by leo1756 on Jan 23, except instead of Close(true), I just use Close() and instead of Save(), I use SaveAs(const QString&) with the desired filename. I’ve read tons of posts about this all over the internet and on different forums but none of the solutions seem to be working for me.
You must log in to post a reply. Not a member yet? Register here!


