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
Code:
ui
->excel
=new QAxWidget("Excel.Application");
ui->gridLayout->addWidget(ui->excel);
//ui->excel->querySubObject("WorkBooks")->dynamicCall("Open (const QString&)", QString("c:\\test\\book.xlsx"));
ui->excel->setControl("c:\\test\\book.xlsx");
ui->excel->querySubObject("ActiveWorkBook");
ui->excel->setProperty("Visible", true);
ui->excel->setProperty("Caption", "Qt Excel"); //Titled Qt Excel
ui->excel->setProperty("DisplayAlerts", true);
ui->excel->setProperty("DisplayFullScreen", false);
ui->excel->dynamicCall("CommandBars("MyToolbar").Enabled = true");
ui->excel->dynamicCall("CommandBars("Worksheet Menu Bar").Enabled = true");
ui->excel->dynamicCall("CommandBars("MyToolbar").Enabled = true");
ui->excel->dynamicCall("CommandBars("Worksheet Menu Bar").Visible = true");
ui->excel->dynamicCall("show.toolbar("Ribbon",True");
Re: Embed Excel in QT window with toolbars showing
Code:
ui->excel->dynamicCall("CommandBars("MyToolbar").Enabled = true");
ui->excel->dynamicCall("CommandBars("Worksheet Menu Bar").Enabled = true");
ui->excel->dynamicCall("CommandBars("MyToolbar").Enabled = true");
ui->excel->dynamicCall("CommandBars("Worksheet Menu Bar").Visible = true");
ui->excel->dynamicCall("show.toolbar("Ribbon",True");
The first thing I would try is to correctly escape the double-quotes inside the argument to dynamicCall, e.g.
Code:
ui->excel->dynamicCall("CommandBars(\"MyToolbar\").Enabled = true");
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.
Re: Embed Excel in QT window with toolbars showing
Quote:
Originally Posted by
ChrisW67
Code:
ui->excel->dynamicCall("CommandBars("MyToolbar").Enabled = true");
ui->excel->dynamicCall("CommandBars("Worksheet Menu Bar").Enabled = true");
ui->excel->dynamicCall("CommandBars("MyToolbar").Enabled = true");
ui->excel->dynamicCall("CommandBars("Worksheet Menu Bar").Visible = true");
ui->excel->dynamicCall("show.toolbar("Ribbon",True");
The first thing I would try is to correctly escape the double-quotes inside the argument to dynamicCall, e.g.
Code:
ui->excel->dynamicCall("CommandBars(\"MyToolbar\").Enabled = true");
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 :(