Results 1 to 8 of 8

Thread: ActiveQt + Excel

  1. #1
    Join Date
    Sep 2007
    Posts
    19
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default ActiveQt + Excel

    I'm trying to convert Excel file to DBF. So i'm using ActiveQt FrameWork.
    So i generated Excel namespace by using dumpcpp tool.
    First of all i wanted to get list of the Worksheets.
    The application is getting access violation in the row #10:
    QString sheetname = sheet->Name();
    I think the problem is that i incorrectly get the Excel::Worksheet object.

    Does anybody know how to solve this problem?

    The source code is shown below
    Qt Code:
    1. Excel::Application* excel = new Excel::Application;
    2. Excel::Workbooks* wbks = excel->Workbooks();
    3. Excel::Workbook* wbk = wbks->Open(exchange->getFilename());
    4. Excel::Sheets* sheets = wbk->Worksheets();
    5. int count = sheets->Count();
    6. QStringList sheetsList;
    7. for (int i=1; i<=count; i++)
    8. {
    9. Excel::Worksheet* sheet = (Excel::Worksheet*) sheets->Item(i);
    10. QString sheetname = sheet->Name();
    11. sheetsList.append(sheetname);
    12. }
    13. wbk->Close();
    14. excel->Quit();
    To copy to clipboard, switch view to plain text mode 

    Thanks.
    Last edited by nile.one; 18th September 2007 at 07:17.

  2. #2
    Join Date
    Sep 2007
    Posts
    19
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ActiveQt + Excel

    So, i've tried to use the QAxObject instead of dumpcpp's generated namespace.
    And that works fine:

    Qt Code:
    1. QAxObject* excel = new QAxObject( "Excel.Application", 0 );
    2. // excel->dynamicCall("SetVisible(bool)",true);
    3. QAxObject *workbooks = excel->querySubObject( "Workbooks" );
    4. QAxObject *workbook = workbooks->querySubObject( "Open(const QString&)", exchange->getFilename() );
    5. QAxObject *sheets = workbook->querySubObject( "Worksheets" );
    6. int count = sheets->dynamicCall("Count()").toInt();
    7. if (0 >= count)
    8. {
    9. excelState = Error;
    10. return;
    11. }
    12. //else
    13. QStringList sheetsList;
    14. for (int i=1; i<=count; i++)
    15. {
    16. QAxObject* sheet = sheets->querySubObject( "Item( int )", i );
    17. QString name = sheet->dynamicCall("Name()").toString();
    18. sheetsList.append(name);
    19. }
    20. workbook->dynamicCall("Close()");
    21. excel->dynamicCall( "Quit()");
    To copy to clipboard, switch view to plain text mode 

    It seems to me that the problem is in dumpcpp...

    Of course, using the QAxObject is possible, but the Excel::Application namespace is much more pleasant to the eyes

  3. #3
    Join Date
    Sep 2007
    Posts
    19
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ActiveQt + Excel

    So i have another problem with ActiveQt and Excel =)

    Does anybody know how to set Excel' cell values by array of data?
    I mean not to call setValue on each cell, but set values of whole Range with only one call.
    It will rapidly speed working with Excel data.

    Well, here are my examples of code, which are unfortunately doesn't work

    Example1, does nothing at all
    Qt Code:
    1. QList<QVariant> lst;
    2. for (int i=1; i<6; i++)
    3. lst.append(i);
    4. range = sheet->querySubObject( "Range(QString, QString)", "V1", "V5" );
    5. QVariant v(lst);
    6. range->dynamicCall("SetValue(QList<QVariant>)", lst);
    To copy to clipboard, switch view to plain text mode 

    Example 2, sets all values only to first value of list
    Qt Code:
    1. QVariant v(lst);
    2.  
    3. range->dynamicCall("SetValue(QVariant)", v);
    To copy to clipboard, switch view to plain text mode 

    Thanks.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: ActiveQt + Excel

    Your questions are a bit out of scope of this forum. You're asking for information about Excel API, which has nothing to do with Qt and I'm afraid we're simply not qualified to answer them.


    BTW. Shouldn't you iterate starting from 0 instead of 1?

  5. #5
    Join Date
    Sep 2007
    Posts
    19
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ActiveQt + Excel

    ok, sorry for offtopic

    BTW. Shouldn't you iterate starting from 0 instead of 1?
    No, Micro$oft starts counting from 1

  6. #6
    Join Date
    Apr 2007
    Location
    Ilsfeld, Germany
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default OT: ActiveQt + Excel

    Hi,

    you can only fill a horizontal range with an 1-dim Array, for a vertical range you need a 2-dim array.

    And, also M$ often counts beginning with 1, here that shouldn't matter.

    In VBA you could code it like this.

    HTH, Bernd
    --
    Qt Code:
    1. Option Explicit
    2.  
    3. Sub x()
    4. Dim i%, arHor(22 To 25), arVer(10 To 12, 99 To 99)
    5.  
    6. For i = 22 To 25
    7. arHor(i) = i
    8. Next
    9. Range("A1:D1") = arHor
    10.  
    11. For i = 10 To 12
    12. arVer(i, 99) = i
    13. Next
    14. Range("A2:A4") = arVer
    15. End Sub
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Sep 2007
    Posts
    19
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ActiveQt + Excel

    Thanks, but unfortunately QAxObject doesn't support 2-dimensional arrays (i.e. QVariant doesn't support)

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: ActiveQt + Excel

    Actually you can make QVariant support basically anything.. See Q_DECLARE_METATYPE for more details.
    J-P Nurmi

Similar Threads

  1. Replies: 3
    Last Post: 7th October 2015, 20:43
  2. How can I Read Write Excel File
    By xingshaoyong in forum Qt Programming
    Replies: 6
    Last Post: 13th July 2011, 21:16
  3. Read excel
    By psipsi in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 18:07
  4. Excel XML Creation with Qt's Dom classes
    By jpujolf in forum Qt Programming
    Replies: 4
    Last Post: 21st May 2007, 13:23
  5. Filtering as Excel in Table
    By ankurjain in forum Qt Programming
    Replies: 1
    Last Post: 13th May 2006, 10:05

Bookmarks

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.