Results 1 to 2 of 2

Thread: is it possible to load QAxobject Excel to initialize and call it later?

  1. #1
    Join Date
    Aug 2019
    Qt products

    Default is it possible to load QAxobject Excel to initialize and call it later?

    I am creating a program that will have the need to call the QAXobject Excel function on different circumstances ( creating , parsing, modifying ) and it works ,
    but it always takes a lot of time loading whenever i call a certain process especially if i have to read/write a 200rows x 50 columns excel file .

    i wonder if it will be possible to call the QAXobject Excel application from the start of the program?
    leave it open and use it when needed ( when parsing rows , saving xls, modifying )

    it is like the idea to call the code from the start:
    Qt Code:
    1. QAxObject* excel = new QAxObject("Excel.Application");
    2. QAxObject* workbooks = excel->querySubObject("WorkBooks");
    To copy to clipboard, switch view to plain text mode 

    and just use the following code when needed
    code example is setting a value of a cell

    Qt Code:
    1. workbooks->querySubObject("Open (const QString&)", filePath);
    2. QAxObject* workbook = excel->querySubObject("ActiveWorkBook")
    3. QAxObject* worksheet = workbook->querySubObject("Worksheets(int)", 1);
    4. QAxObject* cell = worksheet->querySubObject( "Cells( int, int )", rowids, coli);
    5. cell->setProperty("Value", ShipAddi);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 662 Times in 652 Posts
    Qt products
    Windows Android

    Default Re: is it possible to load QAxobject Excel to initialize and call it later?

    It should be possible to do all of this. I have done it in the past with other QAx objects for Word and other ActiveX / COM objects.

    Just remember to match any call that creates a COM instance with a call to delete or close it so the objects (and the files they represent) don't get locked open when your program exits. The easiest way is to use smart pointers wherever possible.

    Note that you are not limited to using QAxObject if you want to use Excel or other ActiveX objects in your Qt programs. Qt is just C++, so anything you can do in an ordinary C++ program you can also do in a Qt-based C++ program.

    You can use the #import directive in your source code to create ".tlb" and ".tli" files that directly create C++ smart pointer interfaces to the ActiveX objects.

    Here is one link that explains how to do that. And here's a link to a PDF document that gives examples starting on page 53.

    In doing it directly as described in the links, you are using smart pointers that will "clean up" after themselves and ensure that everything you access will be properly closed or destroyed.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    ofbrc (16th September 2019)

Similar Threads

  1. [QAxObject] Excel export
    By ado130 in forum Newbie
    Replies: 0
    Last Post: 19th March 2017, 17:11
  2. QAxObject probelm for Write the Excel
    By anh5kor in forum Newbie
    Replies: 3
    Last Post: 3rd March 2016, 17:54
  3. QAxObject Importing Excel named ranges using MS Query
    By simonb in forum Qt Programming
    Replies: 0
    Last Post: 24th July 2012, 09:45
  4. Can't save excel file with QaxObject
    By Mirmilstein in forum Qt Programming
    Replies: 3
    Last Post: 2nd April 2012, 10:05
  5. When to use templates thinking in the speed of the program.
    By tonnot in forum General Programming
    Replies: 1
    Last Post: 22nd June 2011, 11:43

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.