| | |
| | | #include <QDebug> |
| | | #include <QAxObject> |
| | | #include <QFile> |
| | | #include <QDateTime> |
| | | #include <QMessageBox> |
| | | |
| | | #pragma execution_character_set("utf-8") |
| | | ExportToFile::ExportToFile(QObject *parent) : QObject(parent) |
| | |
| | | if(!dir.exists()){ |
| | | demoPath = QDir::currentPath()+"/release/Data/附件2_内审统01表_单位及内部审计机构基本情况表-1.301版_demo.xls"; |
| | | } |
| | | |
| | | QString savePath = QFileDialog::getSaveFileName(nullptr,"保存文件",QDir::currentPath()+"/内审统01表.xls","Excel File(*.xls,*.xlsx)"); |
| | | QString dt = QDateTime::currentDateTime().toString("yyyyMMdd-HHmmss"); |
| | | QString savePath = QFileDialog::getSaveFileName(nullptr,"保存文件",QDir::currentPath()+QString("/内审统01表_%1_%2.xls").arg(QString::fromLocal8Bit(info.name)).arg(dt),"Excel File(*.xls;*.xlsx)"); |
| | | qDebug()<<"savepath:"<<savePath <<endl << "demoPath:"<<demoPath; |
| | | |
| | | |
| | |
| | | wbs->dynamicCall("Close()"); |
| | | excel.dynamicCall("Quit(void)"); |
| | | |
| | | QMessageBox::information(nullptr,"导出完成","文件位置:"+savePath); |
| | | |
| | | } |
| | | return 0; |
| | |
| | | return 0; |
| | | } |
| | | |
| | | int ExportToFile::saveToExcelFromNeiShenZonghe() |
| | | int ExportToFile::saveToExcelFromNeiShenZonghe(QString name,NeiShenZongHeInfo &nszh) |
| | | { |
| | | qDebug()<<"内审综合保存导出"; |
| | | |
| | | if(name.size() == 0) return -1; // 文件为空 |
| | | |
| | | QString demoPath = QDir::currentPath()+"/Data/附件4_内审统03表_内部审计统计综合表_demo.xls"; |
| | | QDir dir(demoPath); |
| | | if(!dir.exists()){ |
| | | demoPath = QDir::currentPath()+"/release/Data/附件4_内审统03表_内部审计统计综合表_demo.xls"; |
| | | } |
| | | QString dt = QDateTime::currentDateTime().toString("yyyyMMdd-HHmmss"); |
| | | QString savePath = QFileDialog::getSaveFileName(nullptr,"保存文件",QDir::currentPath()+QString("/综合表_%1_%2.xls").arg(name).arg(dt),"Excel File(*.xls;*.xlsx)"); |
| | | qDebug()<<"savepath:"<<savePath << endl << "demoPath:"<<demoPath; |
| | | |
| | | |
| | | |
| | | if(savePath.size() > 0){ |
| | | QAxObject excel("ket.Application"); |
| | | if(!excel.setControl("ket" |
| | | ".Application")){ // windows内核 |
| | | excel.setControl("Excel.Application"); // wps内核 |
| | | } |
| | | |
| | | excel.setProperty("Visible",false); |
| | | excel.setProperty("DisplayAlerts",false); |
| | | QAxObject * wbs = excel.querySubObject("WorkBooks"); |
| | | qDebug()<<"wbs:"<<wbs->className(); |
| | | QAxObject * wb = wbs->querySubObject("Open(QString&)",demoPath); |
| | | qDebug()<<"wb open ok"; |
| | | QAxObject * shs = wb->querySubObject("WorkSheets"); // WorkSheets 也可以 |
| | | // 获取具体表格,行列 |
| | | QAxObject * sheet = shs->querySubObject("Item(int)", 1); // 第一个表 |
| | | QAxObject *usedRange = sheet->querySubObject("UsedRange"); |
| | | int rows = usedRange->querySubObject("Rows")->property("Count").toInt(); |
| | | int columns = usedRange->querySubObject("Columns")->property("Count").toInt(); |
| | | qDebug()<<"r--c:"<<rows<<columns; |
| | | |
| | | // 修改内容 |
| | | |
| | | // 四 项目审计 单位 个 |
| | | char index[5]={'G','H','I','J','K'}; |
| | | |
| | | for(int i=0;i<5;++i){ |
| | | QString cellStr = QString("%1%2").arg(index[i]).arg(40); |
| | | qDebug()<<cellStr<<nszh.code_030300[i]; |
| | | qDebug()<<"修改之前:"<<sheet->querySubObject("Range(QVariant, QVariant)", cellStr)->property("Value2").toInt(); |
| | | sheet->querySubObject("Range(QVariant, QVariant)", cellStr)->setProperty("Value2", nszh.code_030300[i]); // 审计项目 |
| | | qDebug()<<"修改结果:"<<sheet->querySubObject("Range(QVariant, QVariant)", cellStr)->property("Value2").toInt(); |
| | | } |
| | | for(int i=0;i<5;++i){ |
| | | sheet->querySubObject("Range(QVariant, QVariant)", QString("%1%2").arg(index[i]).arg(41))->setProperty("Value2", nszh.code_030301[i]); // 其中:贯彻落实国家重大政策措施审计 |
| | | } |
| | | |
| | | qDebug()<<40; |
| | | |
| | | |
| | | // 完事了,结束,保存或者退出 |
| | | wb->dynamicCall("SaveAs(const QString&)",QDir::toNativeSeparators(savePath)); |
| | | wbs->dynamicCall("Close()"); |
| | | excel.dynamicCall("Quit(void)"); |
| | | |
| | | QMessageBox::information(nullptr,"导出完成","文件位置:"+savePath); |
| | | |
| | | } |
| | | |
| | | return 0; |
| | | } |