Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QAxObject and Excel Save as CSV



  •     QAxObject excel("Excel.Application");
        excel.setProperty("Visible", true);    
        QAxObject * workBooks = excel.querySubObject("WorkBooks");
        workBooks->dynamicCall("Open(const QString&)", QString("F:/ExcelAction/test.xlsx"));
        workBooks->dynamicCall("SaveAs(const QString&)", QString("./test2018.csv"));
        workBooks->dynamicCall("Close (Boolean)", false); 
        excel.dynamicCall("Quit(void)");
    

    when running it,the output warning showed below :

    QAxBase::dynamicCallHelper: SaveAs(QString): No such property in  [unknown]
    	Candidates are:
    QAxBase: Error calling IDispatch member Close: Unknown error
    

    Anyone know the bug 's solutions thanks !



  • @pyuxing

    like this:

    QAxObject   *workbook = workBooks->querySubObject("Open(const QString&)", QString("F:/ExcelAction/test.xlsx"));
    workbook->dynamicCall("SaveAs(const QString&, int)", QDir::toNativeSeparators("./test2018.csv"), 6); // 6 = XlFileFormat::xlCSV
    


  • @Devopia53 Thanks for your reply !
    I have done as you said ,but there is problem as before.

    QAxBase::dynamicCallHelper: Save(QString,int): No such property in  [unknown]
    	Candidates are:
    QAxBase: Error calling IDispatch member Close: Unknown error
    


  • The code was showed below:

    int main(int argc, char *argv[])
    {
       // QCoreApplication a(argc, argv);
        QApplication a(argc, argv);
        CoInitializeEx(NULL, COINIT_MULTITHREADED);
        QAxObject excel("Excel.Application");
        excel.setProperty("Visible", false);  
        QAxObject * workBooks = excel.querySubObject("WorkBooks");
        workBooks->dynamicCall("Open(const QString&)", QString("F:/ExcelAction/test2018.xlsx"));
        QVariant titleValue = excel.property("Caption");    
        qDebug() << "excel title : " << titleValue;
        QAxObject * workBook = excel.querySubObject("ActiveWorkBook");
        QAxObject * workSheets = workBook->querySubObject("Sheets");    
    
        //QVariant returnValue;
        workBooks->dynamicCall("SaveAS(const QString&, int)", QDir::toNativeSeparators("F:\ExcelAction\test2018.csv"), 6);
    
        workBooks->dynamicCall("Close (Boolean)", false);
        excel.dynamicCall("Quit(void)");
        return a.exec();
    }
    

  • Qt Champions 2019

    @pyuxing What about SaveAs(QString,int) as @Devopia53 showed?



  • @jsulm
    like this:

    QAxBase::dynamicCallHelper: SaveAS(QString&,int): No such property in  [unknown]
    	Candidates are:
    QAxBase: Error calling IDispatch member Close: Unknown error
    


  • @pyuxing

    Method Open() and Close() are defined in the WorkBooks object.
    Method Save() and SaveAs() are defined in the WorkBook object.



  • @Devopia53
    Thanks a lot,with your help I have solved the problem now.


Log in to reply