View Full Version : QAxWidget embed excel into QDialog

21st October 2013, 14:37
Hello everybody,
I started to read similar posts and I try to apply it but without success.
I need to open an excel file (that contains macro and use an INI file) into my application, embedding it into it.
I design a widget, and I promoted it to QAxWidget, after that I create this code to use the file:


//QAxObject * workbooks = ui->excel->querySubObject("WorkBooks");
//workbooks->dynamicCall("Open (const QString&)", srcfile);
//QAxObject * workbook = workbooks->querySubObject("ActiveWorkBook");

QAxObject * worksheet = ui->excel->querySubObject("Worksheets(1)");
QAxObject * piva, * tipo, * data, * num, * scad, * tot;

//ui->excel->setProperty("Visible", false);

int i=0;
while (qry->next()){

piva = worksheet->querySubObject("Cells(int,int)", i+2,1);
tipo = worksheet->querySubObject("Cells(int,int)", i+2,3);
data = worksheet->querySubObject("Cells(int,int)", i+2,4);
num = worksheet->querySubObject("Cells(int,int)", i+2,5);
scad = worksheet->querySubObject("Cells(int,int)", i+2,6);
tot = worksheet->querySubObject("Cells(int,int)", i+2,7);

if (qry->value(2).toString().startsWith('N'))

QDate dtData,dtScad;

//num->setProperty("Value",QString("%1 %2").arg(qry->value(2).toString()).arg(qry->value(3).toString()));




ui->excel->setProperty("DisplayAlerts", false);
ui->excel->dynamicCall("Run(QVariant)", "ckCampi");

When I enter the while I got Segmentation Fault error, and my application say QAxBase::dynamicCallHelper: Object does not support automation.

Where is the mistake?

I've also verified that If I run Macro that use INI file that not respond, as if the file was moved, the file is loaded in any qt system path? Which one? The ini file is correctly configured and positioned into the same path of excel file (as it should be!).

Have you got any ideas?

Thanks a lot for your time


20th November 2013, 17:37
I've got other test and we have two scenarios:
1) If I use QAxWidget->setControl("C:\file.xls") I see the sheet into my control (as I like) but... I can't fill its cells programmaticaly: the querySubObject() and dynamicCall() aren't available in this configuration and raise segmentation fault error.
2) If I use QAxWidget->setControl("Excel.Application") I can work programmatically on my excel file, but... the file won't embedded into my QAxWidget that it remain white.

So, how can Got the 1.5 possibility ;)? How programmatically change a file embedded by setControl()? :confused:

Thanks a lot for your time


PS. I've opensource version of QT