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



  • Do you use Active Qt? Not that I'm familiar with that, but someone else might be.



  • 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);
    range->setProperty("Value", QVariant(1234));
    
    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.



  • Hello musto,

    I will try that and post the result later.
    Actually I've noticed that this problem is not specific to QT since I have seen people complaining about this issue on many foruns of other languages and platforms too.
    Anyway I will try as you suggested and see if it works.

    Thank you.

    Leo



  • Hi Leo
    In this forum has already discussed Qt and Excel "here":http://developer.qt.nokia.com/forums/viewthread/1871/.
    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.



  • I have the same problem, but it is related to Windows 8. I also think that it is not Qt-specific because a Delphi-code causes the same problems in my simple example. I tried a lot of different things, played with the function parameters, etc. but nothing helped. On Windows 7 everything worked.

    See: http://stackoverflow.com/questions/21632838/windows-8-qt-word-automation-does-not-clean-up-background-process-winword-exe

    Did you find a solution?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.