Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt and MS Excel
Forum Updated to NodeBB v4.3 + New Features

Qt and MS Excel

Scheduled Pinned Locked Moved General and Desktop
8 Posts 6 Posters 16.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leo1756
    wrote on 20 Jan 2012, 16:19 last edited by
    #1

    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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on 22 Jan 2012, 00:18 last edited by
      #2

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

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • L Offline
        L Offline
        leo1756
        wrote on 23 Jan 2012, 12:59 last edited by
        #3

        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

        1 Reply Last reply
        0
        • M Offline
          M Offline
          musto
          wrote on 22 Feb 2012, 07:30 last edited by
          #4

          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.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            leo1756
            wrote on 23 Feb 2012, 11:31 last edited by
            #5

            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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Skyrim
              wrote on 23 Feb 2012, 14:59 last edited by
              #6

              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;
              @

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SKolaMunn
                wrote on 21 May 2012, 14:22 last edited by
                #7

                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.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  anagelcg
                  wrote on 12 Feb 2014, 11:49 last edited by
                  #8

                  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?

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved