Here's some code that can get you started. I must stress, that I don't fully understand it, since I copied and pasted it from somewhere else - and then started to screw around with it. So don't ask me to explain in depth. The comments in here are what I THINK happens.
I still need to create a QAxWidget for some reason, even though I only want to read and not display the excel file. If anyone knows how I can get around using a QApplication and a QAxWidget object and still have this work: please let me know.
#include <qaxobject>
#include <qaxwidget>
#include <qapplication>
int main(int argc, char *argv[])
{
const char* cp = "Range(E11)";
// because I want to read the file - not display it.
excel.setProperty("Visible", false);
QAxObject *workbooks
= excel.
querySubObject("WorkBooks");
workbooks
->dynamicCall
("Open (const QString&)",
QString("e:/tmp/test3.xls"));
QAxObject *workbook
= excel.
querySubObject("ActiveWorkBook");
// I need data from the 2nd worksheet (worksheets are numbered starting from 1)
QAxObject *worksheet
= workbook
->querySubObject
("Worksheets(int)",
2);
// Read fom the second worksheet the contents of cell E11
QAxObject *range
= worksheet
->querySubObject
(cp
);
strVal = range->property("Value").toString();
// close the excel file
excel.dynamicCall("Quit (void)");
return(0);
}
#include <qaxobject>
#include <qaxwidget>
#include <qapplication>
int main(int argc, char *argv[])
{
QString strVal;
const char* cp = "Range(E11)";
QApplication a(argc, argv);
QAxWidget excel("Excel.Application");
// because I want to read the file - not display it.
excel.setProperty("Visible", false);
QAxObject *workbooks = excel.querySubObject("WorkBooks");
workbooks->dynamicCall("Open (const QString&)", QString("e:/tmp/test3.xls"));
QAxObject *workbook = excel.querySubObject("ActiveWorkBook");
// I need data from the 2nd worksheet (worksheets are numbered starting from 1)
QAxObject *worksheet = workbook->querySubObject("Worksheets(int)", 2);
// Read fom the second worksheet the contents of cell E11
QAxObject *range = worksheet->querySubObject(cp);
strVal = range->property("Value").toString();
// close the excel file
excel.dynamicCall("Quit (void)");
return(0);
}
To copy to clipboard, switch view to plain text mode
Bookmarks