Results 1 to 2 of 2

Thread: Time-Performance problems reading/writing excel files with ActiveQt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Time-Performance problems reading/writing excel files with ActiveQt

    Hi everybody!

    I'm developing with QT an application that will read excel file, make some processing on the data and then rewrite the results on the file itself... Conceptually very simple (the complex part should be the data-processing). I found a good example on the net (probably i found it in this forum, but I don' remember exactly... if it is in this way sorry for the duplication) where it is explained how to read/write excel with QT:

    Qt Code:
    1. #include <QtGui>
    2. #include <QAxObject>
    3. #include <QAxWidget>
    4.  
    5. int main(int argc, char **argv)
    6. {
    7. QApplication a(argc, argv);
    8.  
    9. QAxWidget excel("Excel.Application");
    10. excel.setProperty("Visible", true);
    11.  
    12. QAxObject * workbooks = excel.querySubObject("WorkBooks");
    13. workbooks->dynamicCall("Open (const QString&)", QString("e:/test/test.xls"));
    14. QAxObject * workbook = excel.querySubObject("ActiveWorkBook");
    15. QAxObject * worksheets = workbook->querySubObject("WorkSheets");
    16. int intCount = worksheets->property("Count").toInt();
    17. for (int i = 1; i <= intCount; i++)
    18. {
    19. int intVal;
    20. QAxObject * worksheet = workbook->querySubObject("Worksheets(int)", i);
    21. qDebug() << i << worksheet->property("Name").toString();
    22. QAxObject * range = worksheet->querySubObject("Cells(1,1)");
    23. intVal = range->property("Value").toInt();
    24. range->setProperty("Value", QVariant(intVal+1));
    25.  
    26. QAxObject * range2 = worksheet->querySubObject("Range(C1)");
    27. intVal = range2->property("Value").toInt();
    28. range2->setProperty("Value", QVariant(intVal+1));
    29. }
    30.  
    31. QAxObject * worksheet = workbook->querySubObject("Worksheets(int)", 1);
    32. QAxObject * usedrange = worksheet->querySubObject("UsedRange");
    33. QAxObject * rows = usedrange->querySubObject("Rows");
    34. QAxObject * columns = usedrange->querySubObject("Columns");
    35. int intRowStart = usedrange->property("Row").toInt();
    36. int intColStart = usedrange->property("Column").toInt();
    37. int intCols = columns->property("Count").toInt();
    38. int intRows = rows->property("Count").toInt();
    39.  
    40. for (int i = intRowStart; i < intRowStart + intRows; i++)
    41. {
    42. for (int j = intColStart; j <= intColStart + intCols; j++)
    43. {
    44. QAxObject * range = worksheet->querySubObject("Cells(int,int)", i, j );
    45. qDebug() << i << j << range->property("Value");
    46. }
    47. }
    48. excel.setProperty("DisplayAlerts", 0);
    49. workbook->dynamicCall("SaveAs (const QString&)", QString("e:/test/xlsbyqt.xls"));
    50. excel.setProperty("DisplayAlerts", 1);
    51. workbook->dynamicCall("Close (Boolean)", false);
    52.  
    53. excel.dynamicCall("Quit (void)");
    54. return 0;
    55. }
    To copy to clipboard, switch view to plain text mode 
    This example is working fine in my application (i.e. I'm able to read/write xls files using it) but it has big problems in time-performance.
    I'm working with medium-size files (1MByte, more or less... 6000rows x 40cols, for example). Excel (or OpenOffice) can open the file in a few seconds,
    my application (using the code above) needs about 30 minutes to execute the same operation!!! I have tested it on two different pc.
    So, I "suppose" there is something is not working properly... but i can't find where is the problem
    1. The problem is in the code? I don't think of it... I have looked for other examples and I have almost always found the same code instructions (using "Cells(i, j)").
    2. The problem is in the "settings" of my pc? I'm using VisualStudio 2010, Qt 4.8.1 open source, Office 2010.
    3. The problem is in QT itself? Maybe it isn't the right solution for this kind of program...

    Does anybody know something more about it?

    In the meantime I have found a work-around to read the data from excel file: I save the sheets of the xls in different csv files and then I parse them.
    It is working but using csv is leading to other problems:
    1. Different separators/delimiters. For example, my home pc uses the comma "," and the office-pc uses the semicolon ";".
    2. How to load (programmatically, of course) the csv files (that i modified after the data-processing) in different sheets of one single xls file?
    3. Even if I find a way to merge the csv files in on xls, how to apply on the new xls the same formatting of the original xls?.

    Thanks in advance... helps and suggestions will be appreciated!
    Cyrano
    Last edited by high_flyer; 29th June 2012 at 11:49. Reason: code tags

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: Time-Performance problems reading/writing excel files with ActiveQt

    I would do the following:
    1) Remove the debug messages from the loops - there is quite a lot of those and they can be quite slow...
    2) If that doesn't solve the problem, remove parts of the code to locate the bottleneck -- one of the loops first

Similar Threads

  1. ActiveQT + Excel charts
    By cia.michele in forum Qt Programming
    Replies: 9
    Last Post: 2nd November 2016, 13:54
  2. Replies: 2
    Last Post: 23rd July 2010, 14:53
  3. ActiveQt hosting Excel sheet
    By ArmanS in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2010, 10:27
  4. Replies: 3
    Last Post: 12th June 2008, 11:59
  5. ActiveQt + Excel
    By nile.one in forum Qt Programming
    Replies: 7
    Last Post: 19th October 2007, 22:58

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
  •  
Qt is a trademark of The Qt Company.