PDA

View Full Version : QAxObject probelm for Write the Excel



anh5kor
11th December 2015, 13:44
I want to write the content to excel sheet.
I saw one thread in Qt about Read and Write Excel.

http://www.qtcentre.org/threads/8288-How-can-I-Read-Write-Excel-File

That described Excel reading via QAxObject.
But when I #include <QAxObject> in my Qt code.My compiler complain "No such file and directory.

So I am not able to write the code given below


QAxObject* excel = new QAxObject( "Excel.Application", 0 );
QAxObject* workbooks = excel->querySubObject( "Workbooks" );
QAxObject* workbook = workbooks->querySubObject( "Open(const QString&)", exchange->getFilename() );
QAxObject* sheets = workbook->querySubObject( "Worksheets" );

Please let me know how can I read and write an excel by using the above method or any other method.

Added after 47 minutes:

The above Query is solved.I have added the below two line.
"CONFIG += qaxcontainer" to pro file and added
#include <ActiveQt/QAxObject> as header and my code is working fine.

But I am getting problem in creating the Excel file.
The code on the above link shows how to open a excel file already created.
But I want that my code should create and save the excel to specific location.

Please let me know how can I achieve the same.

d_stranz
11th December 2015, 17:48
Please let me know how can I achieve the same.

You need to look in the Excel SDK documentation or the Excel type library (tlb or tli) file. There is an "Add" method for the Workbooks object which will create a Workbook with an ActiveSheet instance. You can then probably use a Save or SaveAs method on the Workbook to save it to a file of your own choosing.

No, I won't give you example code. Teach yourself to fish, don't expect people to put fish in front of you, ready to eat.

sharayu
3rd March 2016, 10:35
Hi,
I am facing problem in passing filename to workbook->dynamiccall()
i want to pass the filename i will get by using QFileDialog::getSaveFileName()

it will not get file path if i will pass returned file name as QString
please help

thnks,
sharayu

d_stranz
3rd March 2016, 16:54
Maybe if you told us what arguments "dynamiccall()" expects and what you are sending it would be easier to help you.