Results 1 to 3 of 3

Thread: Embed Excel in QT window with toolbars showing

  1. #1
    Join Date
    Apr 2021
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Embed Excel in QT window with toolbars showing

    Hi,

    Have spent several days trying things from numerous threads on this forum but cannot seem to get the result I need.

    I need to embed excel within a QT window, showing all excel toolbars as well as the spreadsheet cells. Excel must show within a QT window rather than launching a new instance of Excel.

    If I open the desired spreadsheet file directly i.e. ui->excel->setControl("c:\\test\\book.xlsx"); then the spreadsheet displays within the QAxWidget - which is good, but the toolbars are hidden and I cannot seem to make them visible (some attempts below). If I use ui->excel=new QAxWidget("Excel.Application") then open the spreadsheet using ui->excel->querySubObject("WorkBooks")->dynamicCall("Open (const QString&)", QString("c:\\test\\book.xlsx")); the Excel toolbars are visible but Excel is in a separate window and excel is shown in the taskbar rather than being embedded within QT.

    Any help would be greatly appreciated!!

    Thanks


    Qt Code:
    1. ui->excel=new QAxWidget("Excel.Application");
    2. ui->gridLayout->addWidget(ui->excel);
    3. //ui->excel->querySubObject("WorkBooks")->dynamicCall("Open (const QString&)", QString("c:\\test\\book.xlsx"));
    4. ui->excel->setControl("c:\\test\\book.xlsx");
    5. ui->excel->querySubObject("ActiveWorkBook");
    6. ui->excel->setProperty("Visible", true);
    7. ui->excel->setProperty("Caption", "Qt Excel"); //Titled Qt Excel
    8. ui->excel->setProperty("DisplayAlerts", true);
    9. ui->excel->setProperty("DisplayFullScreen", false);
    10. ui->excel->dynamicCall("CommandBars("MyToolbar").Enabled = true");
    11. ui->excel->dynamicCall("CommandBars("Worksheet Menu Bar").Enabled = true");
    12. ui->excel->dynamicCall("CommandBars("MyToolbar").Enabled = true");
    13. ui->excel->dynamicCall("CommandBars("Worksheet Menu Bar").Visible = true");
    14. ui->excel->dynamicCall("show.toolbar("Ribbon",True");
    To copy to clipboard, switch view to plain text mode 
    Last edited by d_stranz; 10th April 2021 at 00:40. Reason: missing [code] tags

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Embed Excel in QT window with toolbars showing

    Qt Code:
    1. ui->excel->dynamicCall("CommandBars("MyToolbar").Enabled = true");
    2. ui->excel->dynamicCall("CommandBars("Worksheet Menu Bar").Enabled = true");
    3. ui->excel->dynamicCall("CommandBars("MyToolbar").Enabled = true");
    4. ui->excel->dynamicCall("CommandBars("Worksheet Menu Bar").Visible = true");
    5. ui->excel->dynamicCall("show.toolbar("Ribbon",True");
    To copy to clipboard, switch view to plain text mode 


    The first thing I would try is to correctly escape the double-quotes inside the argument to dynamicCall, e.g.
    Qt Code:
    1. ui->excel->dynamicCall("CommandBars(\"MyToolbar\").Enabled = true");
    To copy to clipboard, switch view to plain text mode 


    I do not have the required environment to try any of this but have used ActiveX in Qt before. I have been able to use it more easily with a suitable type library. Maybe you should look at the ActiveQt tool dumpccp and the TYPELIBS qmake variable.

  3. #3
    Join Date
    Apr 2021
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Embed Excel in QT window with toolbars showing

    Quote Originally Posted by ChrisW67 View Post
    Qt Code:
    1. ui->excel->dynamicCall("CommandBars("MyToolbar").Enabled = true");
    2. ui->excel->dynamicCall("CommandBars("Worksheet Menu Bar").Enabled = true");
    3. ui->excel->dynamicCall("CommandBars("MyToolbar").Enabled = true");
    4. ui->excel->dynamicCall("CommandBars("Worksheet Menu Bar").Visible = true");
    5. ui->excel->dynamicCall("show.toolbar("Ribbon",True");
    To copy to clipboard, switch view to plain text mode 


    The first thing I would try is to correctly escape the double-quotes inside the argument to dynamicCall, e.g.
    Qt Code:
    1. ui->excel->dynamicCall("CommandBars(\"MyToolbar\").Enabled = true");
    To copy to clipboard, switch view to plain text mode 


    I do not have the required environment to try any of this but have used ActiveX in Qt before. I have been able to use it more easily with a suitable type library. Maybe you should look at the ActiveQt tool dumpccp and the TYPELIBS qmake variable.
    Hi, thanks for the reply. My actual code does have the correct escape characters but unfortunately this seems to have been lost when cut/pasting to the forum for some reason

Similar Threads

  1. QAxWidget embed excel into QDialog
    By cia.michele in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2013, 17:37
  2. how to embed excelin qt window
    By honey25 in forum Newbie
    Replies: 0
    Last Post: 14th September 2012, 12:37
  3. Replies: 10
    Last Post: 11th June 2012, 10:16
  4. Hiding ToolBars/Docks From Main window
    By ComaWhite in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2010, 05:32
  5. Embed QWebView into non-QT Win32 window (whole window)
    By sonusingh in forum Qt Programming
    Replies: 0
    Last Post: 29th January 2010, 12:40

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.