Results 1 to 17 of 17

Thread: copy/move excel sheet with QT

  1. #1

    Default copy/move excel sheet with QT

    Hi all


    I manipulate excel with qt an all is working almost well.

    Just one issue : I don't success to cpoy/move a sheet in the current workbook

    I have try :
    sheet->dynamicCall("Copy");
    sheet->dynamicCall("Move");

    but the result is a copy/move to a new workbook

    HOw can I solve this?

    Thanks



    Qt Code:
    1. QAxObject* sheet;
    2. QStringList sheets_name;
    3. QAxObject* workbooks;
    4. QAxObject* workbook;
    5. QAxObject*sheets;
    6.  
    7. QString campaign_sheet_name;
    8. QAxObject * excel_cell ;
    9. QAxWidget* excel;
    10.  
    11. qint16 xl_test_start_line = 16;
    12. qint16 sheet_number;
    13.  
    14. //Launch Excel
    15. if (ui->check_button_excel->isChecked())
    16. {
    17. excel = new QAxWidget("Excel.Application");
    18. workbooks = excel->querySubObject( "Workbooks" );
    19. workbook = workbooks->querySubObject( "Open(const QString&)",excel_path );
    20. sheets = workbook->querySubObject( "Worksheets" );
    21. if ( ui->radioButton_XLVisible->isChecked())
    22. excel->setProperty("Visible", true);
    23. int count = sheets->dynamicCall("Count()").toInt();
    24. count = sheets->property("Count").toInt();
    25.  
    26. //Get sheets name list
    27. for (int i = 1; i <= count; i++)
    28. {
    29. QAxObject * worksheet = workbook->querySubObject("Worksheets(int)", i);
    30. sheets_name.push_back(worksheet->property("Name").toString());
    31. number_of_test.push_back(0);
    32. }
    33. sheet = sheets->querySubObject( "Item( int )", 5 );
    34. }
    35.  
    36. sheet->dynamicCall("Copy");
    To copy to clipboard, switch view to plain text mode 
    Last edited by gerardpuducul; 24th October 2012 at 09:18.

  2. #2

    Default Re: copy/move excel sheet with QT

    Nobody has met this kind of issue?

    Any suggestion?

    Thanks

  3. #3
    Join Date
    Nov 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: copy/move excel sheet with QT

    I think you may have to pass the before and after parameters into the copy method. otherwise, the sheet will be copied to a new workbook.

  4. #4

    Default Re: copy/move excel sheet with QT

    hi and thanks to spend some time on my problem.
    I had already think about using Before and after parameter but don't success to do anything
    HOw can I pass this parameter?

    I had try :
    worksheet->dynamicCall("Copy (const QVariant&)","After:=Sheets(3)");
    result :NOTHING COPY
    or
    worksheet->dynamicCall("Copy After:=Sheets(3)");
    result :NOTHING COPY

    Any idea?
    Last edited by gerardpuducul; 19th November 2012 at 13:54.

  5. #5
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: copy/move excel sheet with QT

    the docs are quite clear on how to use arguments with dynamicCall

    http://doc.qt.io/qt-4.8/qaxbase.html

    QVariant one;
    QVariant two;
    worksheet->dynamicCall("Copy", one, two);
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  6. #6

    Default Re: copy/move excel sheet with QT

    thanks for your answer!

    My source code are in post 1. I don't understood why you don't have seen it.

    So I know how to pass arg to dynamic call but i don't success to apply them to have working copy in the same worksheet in excel. ( or maybe argument are wrong)

    But anyway i had try your tipo :

    and replace line 36 of my sources code in post 1
    by
    Qt Code:
    1. QVariant one = "After:=";
    2. QVariant two = "Sheets(5)";
    3. worksheet->dynamicCall("Copy", one, two);
    To copy to clipboard, switch view to plain text mode 

    and nothing is copy

    Any suggestion?

  7. #7
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: copy/move excel sheet with QT

    It looks like you don't know how Copy works.

    here is the help
    http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx


    Looks like this is no longer Qt programming question...
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  8. #8

    Default Re: copy/move excel sheet with QT

    Hi,

    Thanks a lot yours link. It help me to find the solution. I need to pass the object worksheet for before or after parameter;

    so instead of

    Qt Code:
    1. sheet->dynamicCall("Copy");
    To copy to clipboard, switch view to plain text mode 

    I do

    Qt Code:
    1. worksheet_copy_after = sheets->querySubObject("Item( int )", 5 );
    2. QVariant param1 = worksheet_copy_after->asVariant();
    3. worksheet_to_copy->dynamicCall("Copy (const QVariant&)",param1);
    To copy to clipboard, switch view to plain text mode 

    and the copy occurs in the same worksheets!!!

    Thanks

  9. #9

    Default Re: copy/move excel sheet with QT

    In fact I success to copy before but not After

    according to : http://msdn.microsoft.com/en-US/libr...(v=vs.80).aspx

    I try to pass en empty Qvaraint to the first parameter but nothing happen.

    Qt Code:
    1. worksheet_copy_after = sheets->querySubObject("Item( int )", 5 );
    2. QVariant param1 = "missing";
    3. QVariant param2 = worksheet_copy_after->asVariant();
    4. worksheet_to_copy->dynamicCall("Copy (const QVariant&, const QVariant&)",param1,param2);
    To copy to clipboard, switch view to plain text mode 

    How can I do?

    Thanks

  10. #10
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: copy/move excel sheet with QT

    use a null QVariant, not a QVariant with a string="missing"
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  11. #11

    Default Re: copy/move excel sheet with QT

    I had already try with NULL variant (and a lot of stupid test that i prefer to not post here)

    but nothing is working

    Qt Code:
    1. worksheet_copy_after = sheets->querySubObject("Item( int )", 5 );
    2. QVariant param1 = NULL;
    3. QVariant param2 = worksheet_copy_after->asVariant();
    4. worksheet_to_copy->dynamicCall("Copy (const QVariant&, const QVariant&)",param1,param2);
    To copy to clipboard, switch view to plain text mode 

    any suggestion?

    thanks

  12. #12
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: copy/move excel sheet with QT

    QVariant param1 = NULL;

    does that even compile? I don't believe it is a null variant though - if it compiles it will be a QVariant of type string with string = "", or a QVariant of type int with value = 0, or something like that.

    This is how you make a null variant:

    QVariant param;
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  13. #13

    Default Re: copy/move excel sheet with QT

    Of course it compiles. I will not post something which not compile.

    Qt Code:
    1. worksheet_copy_after = sheets->querySubObject("Item( int )", 5 );
    2. QVariant param1;
    3. QVariant param2 = worksheet_copy_after->asVariant();
    4. worksheet_to_copy->dynamicCall("Copy (const QVariant&, const QVariant&)",param1,param2);
    To copy to clipboard, switch view to plain text mode 

    Doesn't work anymore!

  14. #14
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: copy/move excel sheet with QT

    only this idea, I don't know if it will work at all:

    Qt Code:
    1. QString after = worksheet_copy_after->asVariant().toString(); // don't know if this works!
    2. QString call("Copy(missing,%1)");
    3. call = call.arg(after);
    4.  
    5. activeX->dynamicCall(call.toLatin1().constData());
    To copy to clipboard, switch view to plain text mode 

    I thought of that after reading http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx and http://qt-project.org/doc/qt-4.8/qax...ml#dynamicCall. The problem is how to deal with 'missing' correctly. If you can think of some way to access System.Type.Missing then that will probably help.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  15. #15
    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: copy/move excel sheet with QT

    Quote Originally Posted by amleto View Post
    QVariant param1 = NULL;

    does that even compile? I don't believe it is a null variant though - if it compiles it will be a QVariant of type string with string = "", or a QVariant of type int with value = 0, or something like that.

    This is how you make a null variant:

    QVariant param;
    NULL is:

    Qt Code:
    1. #define NULL 0L
    To copy to clipboard, switch view to plain text mode 

    therefore this:

    Qt Code:
    1. QVariant param1 = NULL;
    To copy to clipboard, switch view to plain text mode 

    stores an integer of value "0" in the variant.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16

    Default Re: copy/move excel sheet with QT

    Qt Code:
    1. QString after = worksheet_copy_after->asVariant().toString(); // don't know if this works!
    2. QString call("Copy(missing,%1)");
    3. call = call.arg(after);
    To copy to clipboard, switch view to plain text mode 
    seems working !
    Qt Code:
    1. activeX->dynamicCall(call.toLatin1().constData());
    To copy to clipboard, switch view to plain text mode 
    but what is your activeX?

  17. #17
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: copy/move excel sheet with QT

    worksheet_to_copy
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. QSettings: copy from ini to xml? Copy group?
    By TorAn in forum Qt Programming
    Replies: 1
    Last Post: 11th January 2012, 14:51
  2. Problem in Move Move Event Handler.
    By redgoof in forum Qt Programming
    Replies: 0
    Last Post: 7th April 2010, 11:45
  3. ActiveQt hosting Excel sheet
    By ArmanS in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2010, 10:27
  4. How to copy from Excel and paste to QTableView
    By sms in forum Qt Programming
    Replies: 5
    Last Post: 7th February 2009, 03:58
  5. Move Rectangle on mouse Move
    By vermarajeev in forum Qt Programming
    Replies: 24
    Last Post: 14th May 2007, 05:34

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.