Has anyone tried to automate the older versions of Excel? Like Excel 97? Because it doesn't seem to work the same as the newew ones, particularly Excel XP. For example, the dumpdoc tool doesn't list for it even the Workbooks IDispatch object, which I've grown accustomed to using when opening Excel files. Just like in your examples there, through querySubObject(). Any help woud be appreciated. smile
This is how I initialize Excel, and it works:
bool cMSExcelAutomation::initializeExcel97(bool isVisible)
{
try {
if ( !m_excel ) {
msg
= QObject::tr("Ei saatu instantioitua Excel-oliota (%1)").
arg(EXCEL97
);
logWriter().logMsg("cMSExcelAutomation::initializeExcel97", msg);
return false;
}
m_excel->disableEventSink();
// Asetetaan näkyville
m_excel->dynamicCall("SetVisible(bool)",visible);
msg
= QObject::tr("Excel-olio (%1) luotu").
arg(EXCEL97
);
logWriter().logMsg("cMSExcelAutomation::initializeExcel97", msg);
return true;
}
catch (...) {
msg
= QObject::tr("Poikkeus Excel-olion (%1) luomisen yhteydessä").
arg(EXCEL97
);
logWriter().logMsg("cMSExcelAutomation::initializeExcel97", msg);
return false;
}
return false;
}
bool cMSExcelAutomation::initializeExcel97(bool isVisible)
{
QString msg;
try {
m_excel = new QAxObject(EXCEL97);
if ( !m_excel ) {
msg = QObject::tr("Ei saatu instantioitua Excel-oliota (%1)").arg(EXCEL97);
logWriter().logMsg("cMSExcelAutomation::initializeExcel97", msg);
return false;
}
m_excel->disableEventSink();
// Asetetaan näkyville
QVariant visible(isVisible);
m_excel->dynamicCall("SetVisible(bool)",visible);
msg = QObject::tr("Excel-olio (%1) luotu").arg(EXCEL97);
logWriter().logMsg("cMSExcelAutomation::initializeExcel97", msg);
return true;
}
catch (...) {
msg = QObject::tr("Poikkeus Excel-olion (%1) luomisen yhteydessä").arg(EXCEL97);
logWriter().logMsg("cMSExcelAutomation::initializeExcel97", msg);
return false;
}
return false;
}
To copy to clipboard, switch view to plain text mode
This is how I try to open a workbook, and it fails on Excel97:
bool cMSExcelAutomation
::openWorkBook(QString filename
) {
logWriter().logMsg("cMSExcelAutomation::openWorkBook","Avataan haluttu Excel-tiedosto.");
m_workbookCollection = m_excel->querySubObject( "Workbooks" );
if(!m_workbookCollection)
{
logWriter().logMsg("cMSExcelAutomation::openWorkBook", "Ei saatu luotua objektia 'Workbooks'");
return false;
}
QVariant temp
(filename
);
// Required. An expression that returns the Workbooks object. //QVariant updateLinks; // Optional Variant.
//QVariant readOnly(true); // Optional Variant. True to open the workbook in read-only mode.
//QVariant Format; // Optional Variant.
//QVariant passWord; // Optional Variant.
//QVariant writeResPassword; // Optional Variant.
//QVariant ignoreReadOnlyRecommended; // Optional Variant.
//QVariant origin; // Optional Variant.
//QVariant delimiter; // Optional Variant.
//QVariant editable; // Optional Variant.
//QVariant notify; // Optional Variant.
//QVariant converter; // Optional Variant.
//QVariant addToMru; // Optional Variant.
//QVariant local; // Optional Variant.
//QVariant corruptLoad; // Optional Variant.
//QVariant openConflictDocument; // Optional Variant.
m_workbook = m_workbookCollection->querySubObject("Open(const QVariant&)", temp);
if(!m_workbook)
{
logWriter().logMsg("cMSExcelAutomation::openWorkBook", "Ei saatu luotua WorkBook-oliota.");
logWriter().logMsg("cMSExcelAutomation::openWorkBook", "Ei saatu auki tiedostoa:"+filename);
return false;
}
else return true;
}
bool cMSExcelAutomation::openWorkBook(QString filename)
{
logWriter().logMsg("cMSExcelAutomation::openWorkBook","Avataan haluttu Excel-tiedosto.");
m_workbookCollection = m_excel->querySubObject( "Workbooks" );
if(!m_workbookCollection)
{
logWriter().logMsg("cMSExcelAutomation::openWorkBook", "Ei saatu luotua objektia 'Workbooks'");
return false;
}
QVariant temp(filename); // Required. An expression that returns the Workbooks object.
//QVariant updateLinks; // Optional Variant.
//QVariant readOnly(true); // Optional Variant. True to open the workbook in read-only mode.
//QVariant Format; // Optional Variant.
//QVariant passWord; // Optional Variant.
//QVariant writeResPassword; // Optional Variant.
//QVariant ignoreReadOnlyRecommended; // Optional Variant.
//QVariant origin; // Optional Variant.
//QVariant delimiter; // Optional Variant.
//QVariant editable; // Optional Variant.
//QVariant notify; // Optional Variant.
//QVariant converter; // Optional Variant.
//QVariant addToMru; // Optional Variant.
//QVariant local; // Optional Variant.
//QVariant corruptLoad; // Optional Variant.
//QVariant openConflictDocument; // Optional Variant.
m_workbook = m_workbookCollection->querySubObject("Open(const QVariant&)", temp);
if(!m_workbook)
{
logWriter().logMsg("cMSExcelAutomation::openWorkBook", "Ei saatu luotua WorkBook-oliota.");
logWriter().logMsg("cMSExcelAutomation::openWorkBook", "Ei saatu auki tiedostoa:"+filename);
return false;
}
else return true;
}
To copy to clipboard, switch view to plain text mode
Bookmarks