0

when trying to open a *.xls file using activeQt and the code:

QAxObject *excel = new QAxObject("Excel.Application", this);
QAxObject *workbooks = excel->querySubObject("Workbooks");
QAxObject *workbook = workbooks->querySubObject("Open(const QString&)", "c:\\somefile.xls");
QAxObject *worksheets = workbook->querySubObject("Worksheets");
QAxObject *worksheet = worksheets->querySubObject("Item(int)", 1);

I get an error:

QAxBase: Error calling IDispatch member Open: Unknown error

The program has unexpectedly finished.

I have searched the internet and found out that if the excel has the property Visible set to true, everything gonna workout smoothly with no error. the funny part is that i have to set this property before opening the file otherwise the program gonna crush. However if I set it to true after opening the file, the excel app will show up correctly (showing me the data in the file) but the program will crush.

I am looking for a real solution, or the cause of the problem. I don't want the excel to be visible to the user at anytime.

so making it visible and then invisible is not a satisfying solution for me

p.s. the same code used to work 100% correctly for a whole month on my laptop, and then it started to crush. On my workplace they have the same problem on a pc, so my coworker used to run his apps on my pc to check if they work. it is a bad habit since we don't know what the situation will be for the user

I am using Qt 5.8.0, MS office 2016 and MS office 2012.

Community
  • 1
  • 1
Nour
  • 41
  • 8

1 Answers1

1

I found the solution long time ago, sorry for not updating.

The whole problem was because of the Foxit Pro plugin. I deactivated it in MS office and everything worked fine.

P.S. the problem could be in any MS office application, make sure to turn it off befor using the COM api.

Nico Albers
  • 1,556
  • 1
  • 15
  • 32
Nour
  • 41
  • 8