QString fileName = QFileDialog::getSaveFileName(NULL,"Save File","./saveResult","Excel File (*.xls)");
fileName.replace("/","\\");
QFile file(fileName);
if(file.exists()) {
m_excel = new QExcel(fileName, this);
return false;
}
QAxWidget excel("Excel.Application");
excel.setProperty("Visible",false);
QAxObject * workbooks = excel.querySubObject("WorkBooks");
workbooks->dynamicCall("Add");
QAxObject * workbook = excel.querySubObject("ActiveWorkBook");
workbook->dynamicCall("SaveAs (const QString&,int,const QString&,const QString&,bool,bool)",fileName,56,QString(""),QString(""),false,false);
workbook->dynamicCall("Close (Boolean)", false);
excel.dynamicCall("Quit (void)");
//有几个值得一提的是
//1.getSaveFileName(NULL,"Save File","./saveResult","Excel File (*.xls)") 第三个参数如果直接为. 保存文件名为空, ./saveResult 这样写的话,就有一个默认的名字
//2.
//*******
QAxWidget excel("Excel.Application");
excel.setProperty("Visible",false);
QAxObject * workbooks = excel.querySubObject("WorkBooks");
workbooks->dynamicCall("Add");
QAxObject * workbook = excel.querySubObject("ActiveWorkBook");
workbook->dynamicCall("SaveAs (const QString&,int,const QString&,const QString&,bool,bool)",fileName,56,QString(""),QString(""),false,false);
workbook->dynamicCall("Close (Boolean)", false);
excel.dynamicCall("Quit (void)");
*********//
这里是调用QAxObject 对象的内容,生成一个excel文件。
//3 workbook->dynamicCall("Close (Boolean)", false); 这种调用方式为, 引号内的函数有几个参数, 后面就需要写几个参数, 参数对应的内容要根据帮助文档,自己写