解决QtQAxBase: Error calling IDispatch member SaveAs: Exception thrown by server

workbook->dynamicCall(“SaveAs (const QString &)”, file);file是不能用’/’,如果调QCoreApplication::applicationDirPath()等QT的API获取路径的,都需要调replace(’/’, ‘\’)把’/‘替换成’\’,或者自行把’/‘替换成’\’。

注:workbook的来源

QAxObject *excel = nullptr;   
QAxObject *workbooks = nullptr
QAxObject *workbook = nullptr;
excel = new QAxObject("Excel.Application");

1、通过ActiveWorkBook新建工作簿

workbook = excel->querySubObject("ActiveWorkBook");

2、通过Open打开工作簿

workbooks = excel->querySubObject("WorkBooks");
//workbook  = workbooks->querySubObject("Open(QString&)", path);或
workbook = workbooks->querySubObject("Open(QString, QVariant)",sXlsFile,QVariant(0));

你可能感兴趣的:(QT,excel)