本文是自己再工程里面用到的 亲测有效,绝不会让你吃亏
m_pModelExtInfoSet;m_pModelExtVTerminalConn都是Qt中MVC中的QStandardItemModel 指针
void CopyBayDlg::SlotExportExcel() {
QString file_path = QFileDialog::getSaveFileName(this, tr("Excel File"), \
QString("./IntervalCopy.xlsx"),tr("Excel Files(*.xls *.xlsx)"));
if (file_path.isEmpty()) {
return;
}
QFile file_name(file_path);
if (file_name.exists()) {
file_name.remove();
}
QAxObject *excel = new QAxObject;
if (excel->setControl("Excel.Application")) {
excel->dynamicCall("SetVisible (bool Visible)", false);
excel->setProperty("DisplayAlerts", false);
QAxObject *workbooks = excel->querySubObject("WorkBooks");
workbooks->dynamicCall("Add");
QAxObject *workbook = excel->querySubObject("ActiveWorkBook");
QAxObject *worksheets = workbook->querySubObject("Sheets");
QAxObject *worksheet_ExternalInfoLogic = InsertNewWorkSheet(worksheets, tr(