wumu
2023-09-16 e16e6f0cf090e4d9582bc38439f71a895499cf26
0916
4个文件已修改
1个文件已添加
221 ■■■■■ 已修改文件
internal_system_v1/internal_system_v1.pro 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
internal_system_v1/rcs.qrc 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
internal_system_v1/searchinfo.cpp 156 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
internal_system_v1/searchinfo.h 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
internal_system_v1/searchinfo.ui 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
internal_system_v1/internal_system_v1.pro
@@ -64,3 +64,6 @@
    searchinfo.ui
include(QXlsx/QXlsx.pri)
RESOURCES += \
    rcs.qrc
internal_system_v1/rcs.qrc
New file
@@ -0,0 +1,3 @@
<RCC>
    <qresource prefix="/mayi"/>
</RCC>
internal_system_v1/searchinfo.cpp
@@ -5,6 +5,8 @@
#include <QDir>
#include <QSqlError>
#include <QSqlQuery>
#include <QMessageBox>
#include <QFileDialog>
SearchInfo::SearchInfo(QWidget *parent) :
    QMainWindow(parent),
@@ -192,14 +194,16 @@
void SearchInfo::searchComName()
{
    QSqlQuery query;
    QString sql = QString("select id,name from company_info");
    QString sql = QString("select id,name,code from company_info");
    if(query.exec(sql)){
        qDebug()<<"size:"<<query.numRowsAffected();
        while(query.next()){
            int id = query.value(0).toInt();
            QString name = query.value(1).toString();
            QString code = query.value(2).toString();
            qDebug()<<"com select:"<<id<<name;
            m_comInfo[name] = id;
            m_comCode[name] = code;
            ui->comboBox_company->addItem(name);
        }
    }
@@ -267,6 +271,14 @@
void SearchInfo::on_pushButton_export_clicked()
{
    if(ui->comboBox_company->currentText() == "公司名称"){
        QMessageBox::information(this,"导出错误","请选择一个公司名再导出");
        return;
    }
    if(ui->label_excel_path->text().size() < 5){
        QMessageBox::information(this,"导出设置错误","请先在“导出设置”选择模板及保存文件的路径信息");
        return;
    }
    // 每一张表拿最新的那一批数据即可,然后保存到电子表格中
    int comId = m_comInfo[ui->comboBox_company->currentText()];
    QString audit_project = QString("select kpi_name,code,num from %2 where com_id=%1 limit 10").arg(comId).arg("audit_project");
@@ -289,25 +301,120 @@
    qDebug()<<audit_project_res.size()<<punish_res.size();
    // 操作excel
    QAxObject* excel = new QAxObject("Excel.Application");  // 创建Excel对象
    excel->setProperty("Visible", false);  // 设置Excel不可见
    QAxObject* workbooks = excel->querySubObject("Workbooks");  // 获取所有工作簿
    QAxObject* workbook = workbooks->querySubObject("Add");  // 添加新工作簿
    QAxObject* worksheets = workbook->querySubObject("Worksheets");  // 获取所有工作表
    QAxObject* worksheet = worksheets->querySubObject("Item(int)", 1);  // 获取第一个工作表
    for (int i = 1; i <= 5; i++) {
        for (int j = 1; j <= 5; j++) {
            QString cellValue = "Value";  // 设置要写入的单元格值
            worksheet->querySubObject("Cells(int, int)", i, j)->dynamicCall("SetValue(const QVariant&)", cellValue);  // 写入单元格值
    // 创建新的电子表格
//    QAxObject* excel = new QAxObject("Excel.Application");  // 创建Excel对象
//    excel->setProperty("Visible", false);  // 设置Excel不可见
//    QAxObject* workbooks = excel->querySubObject("Workbooks");  // 获取所有工作簿
//    QAxObject* workbook = workbooks->querySubObject("Add");  // 添加新工作簿
//    QAxObject* worksheets = workbook->querySubObject("Worksheets");  // 获取所有工作表
//    QAxObject* worksheet = worksheets->querySubObject("Item(int)", 1);  // 获取第一个工作表
 //   for (int i = 1; i <= 61; i++) {
//        for (int j = 1; j <= 5; j++) {
//            QString cellValue = "Value";  // 设置要写入的单元格值
//            worksheet->querySubObject("Cells(int, int)", i, j)->dynamicCall("SetValue(const QVariant&)", cellValue);  // 写入单元格值
//        }
    //}
    // 构建一张表:
//    QString cellValue = "单位内部审计业务情况表";  // 设置要写入的单元格值
//    worksheet->querySubObject("Cells(int, int)", 1, 1)->dynamicCall("SetValue(const QVariant&)", cellValue);  // 写入单元格值
//    worksheet->querySubObject("Cells(int, int)", 3, 4)->dynamicCall("SetValue(const QVariant&)", "表  号:");
//    worksheet->querySubObject("Cells(int, int)", 3, 5)->dynamicCall("SetValue(const QVariant&)", "内审统02表");
//    QString path = QDir::currentPath();
//    qDebug()<<"path:"<<path;
//    path += "/debug/Data/save2.xls";
//    qDebug()<<"path:"<<path;
//    workbook->dynamicCall("SaveAs(const QString&)", path);  // 保存工作簿
//    workbook->dynamicCall("Close()");  // 关闭工作簿
//    excel->dynamicCall("Quit()");  // 退出Excel应用程序
//    QMessageBox::information(this,"导出路径信息",path);
    // 打开已存在的电子表格,然后往里写入数据
    // :/mayi/附件3_内审统02表_单位内部审计业务情况表.xls
    QAxObject excel("Excel.Application");
    excel.setProperty("Visible",false);
    excel.setProperty("DisplayAlerts",false);
    //QString str = "D:/Qt/QtP/build-internal_system_v1-Desktop_Qt_5_9_4_MinGW_32bit-Debug/debug/Data/附件3_内审统02表_单位内部审计业务情况表.xls";
    QString str = ui->label_excel_path->text();
    qDebug()<<"open:"<<str;
    qDebug()<<"excel:"<<excel.className();
    QAxObject * wbs = excel.querySubObject("WorkBooks");
    QAxObject * wb = wbs->querySubObject("Open(QString&)",str);
    QAxObject * shs = wb->querySubObject("Sheets"); // WorkSheets 也可以
    int cnt = shs->property("Count").toInt();
    qDebug()<<"cnt="<<cnt;
    for(int i=0;i<cnt;++i){
        QAxObject * sheet = shs->querySubObject("Item(int)", i+1);
        QString sheetName = sheet->property("Name").toString();
        qDebug()<<"sh name:"<<sheetName;
        // 然后再操作表内的数据
        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;
        QVariant  val = usedRange->dynamicCall("Value"); // 拿到二维表格
        QVariantList valRows = val.toList();
        qDebug()<<valRows[11].toList().at(4);
        sheet->querySubObject("Cells(int, int)", 7, 2)->dynamicCall("SetValue(const QVariant&)", ui->comboBox_company->currentText());
        sheet->querySubObject("Cells(int, int)", 6, 2)->dynamicCall("SetValue(const QVariant&)", m_comCode[ui->comboBox_company->currentText()]);
        // 写入审计项目 一
        qDebug()<<"size:"<<audit_project_res.size();
        QString it = audit_project_res[0][2];
        //sheet->querySubObject("Cells(int, int)", 13, 5)->dynamicCall("SetValue(doubule)", 4.5);
        for(int i=0;i<audit_project_res.size();++i){
            sheet->querySubObject("Cells(int, int)", 11+i, 5)->dynamicCall("SetValue(const QVariant&)", audit_project_res[i][2].toDouble());
        }
        // 写入审计工作量 二
        for(int i=0;i<audit_workload_res.size();++i){
            sheet->querySubObject("Cells(int, int)", 21+i, 5)->dynamicCall("SetValue(const QVariant&)", audit_workload_res[i][2].toDouble());
        }
        // 写入问题金额 三
        for(int i=0;i<problem_money_res.size();++i){
            sheet->querySubObject("Cells(int, int)", 22+i, 5)->dynamicCall("SetValue(const QVariant&)", problem_money_res[i][2].toDouble());
        }
        // 写入问题个数 四
        for(int i=0;i<problem_count_res.size();++i){
            sheet->querySubObject("Cells(int, int)", 33+i, 5)->dynamicCall("SetValue(const QVariant&)", problem_count_res[i][2].toDouble());
        }
        // 写入问题整改(金额) 五
        for(int i=0;i<problem_rectification_res.size();++i){
            sheet->querySubObject("Cells(int, int)", 40+i, 5)->dynamicCall("SetValue(const QVariant&)", problem_rectification_res[i][2].toDouble());
        }
        // 写入问题整改(非金额) 六
        for(int i=0;i<problem_no_money_res.size();++i){
            sheet->querySubObject("Cells(int, int)", 47+i, 5)->dynamicCall("SetValue(const QVariant&)", problem_no_money_res[i][2].toDouble());
        }
        // 写入处分 七
        for(int i=0;i<punish_res.size();++i){
            sheet->querySubObject("Cells(int, int)", 52+i, 5)->dynamicCall("SetValue(const QVariant&)", punish_res[i][2].toDouble());
        }
        // 写入案件线索 八
        for(int i=0;i<case_clue_res.size();++i){
            sheet->querySubObject("Cells(int, int)", 56+i, 5)->dynamicCall("SetValue(const QVariant&)", case_clue_res[i][2].toDouble());
        }
    }
    QString path = QDir::currentPath();
    qDebug()<<"path:"<<path;
    path += "/debug/Data/save2.xls";
    qDebug()<<"path:"<<path;
    workbook->dynamicCall("SaveAs(const QString&)", path);  // 保存工作簿
    workbook->dynamicCall("Close()");  // 关闭工作簿
    excel->dynamicCall("Quit()");  // 退出Excel应用程序
    //wb->dynamicCall("Save()");  // 若文件已存在,则直接保存
    //wb->dynamicCall("SaveAs(const QString&)", str);  // 保存工作簿,若文件不存在,则带名字保存
    if(ui->lineEdit_excel_save->text() > 1){
        wb->dynamicCall("SaveAs(const QString&)", ui->lineEdit_excel_save->text());  // 保存工作簿,若文件不存在,则带名字保存
        qDebug()<<"保存到新文件中";
    }else{
        wb->dynamicCall("Save()"); // 直接保存到模板文件中
        qDebug()<<"保存到老文件中";
    }
    wbs->dynamicCall("Close()");
    excel.dynamicCall("Quit(void)");
    QMessageBox::information(this,"导出成功",QString("导出成功,文件路径为:%1").arg(ui->lineEdit_excel_save->text()));
}
@@ -315,3 +422,16 @@
{
    m_model->setHorizontalHeaderLabels(m_labels[arg1]);
}
void SearchInfo::on_toolButton_seleceExcel_clicked()
{
    if(ui->comboBox_company->currentText() == "公司名称"){
        QMessageBox::information(this,"导出设置错误","请选择一个公司名再设置");
        return;
    }
    QString path = QFileDialog::getOpenFileName(this,"选择表格模板:单位内部审计业务情况表","./","excel(*单位内部审计业务情况表.xls)");
    ui->label_excel_path->setText(path);
    QStringList paths = path.split(".");
    QString newPath = paths.at(0)+"_"+ui->comboBox_company->currentText()+"."+paths.at(1);
    ui->lineEdit_excel_save->setText(newPath);
}
internal_system_v1/searchinfo.h
@@ -33,10 +33,13 @@
    void on_comboBox_currentIndexChanged(const QString &arg1);
    void on_toolButton_seleceExcel_clicked();
private:
    Ui::SearchInfo *ui;
    QSqlDatabase m_db;
    QMap<QString,int> m_comInfo;
    QMap<QString,QString> m_comCode;
    QMap<QString,QString> m_itemAndTable;
    QStandardItemModel *m_model;
    QMap<QString,QStringList> m_labels;
internal_system_v1/searchinfo.ui
@@ -14,7 +14,7 @@
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QGridLayout" name="gridLayout">
   <layout class="QGridLayout" name="gridLayout_2">
    <item row="0" column="0">
     <widget class="QGroupBox" name="groupBox">
      <property name="title">
@@ -132,6 +132,60 @@
     </widget>
    </item>
    <item row="1" column="0">
     <widget class="QGroupBox" name="groupBox_2">
      <property name="title">
       <string>导出设置</string>
      </property>
      <layout class="QGridLayout" name="gridLayout">
       <item row="0" column="0">
        <layout class="QHBoxLayout" name="horizontalLayout_2">
         <item>
          <widget class="QToolButton" name="toolButton_seleceExcel">
           <property name="text">
            <string>选择表格模板</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QLabel" name="label_excel_path">
           <property name="minimumSize">
            <size>
             <width>300</width>
             <height>0</height>
            </size>
           </property>
           <property name="text">
            <string/>
           </property>
          </widget>
         </item>
        </layout>
       </item>
       <item row="1" column="0">
        <layout class="QHBoxLayout" name="horizontalLayout_3">
         <item>
          <widget class="QLabel" name="label_3">
           <property name="text">
            <string>保存位置</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QLineEdit" name="lineEdit_excel_save">
           <property name="minimumSize">
            <size>
             <width>300</width>
             <height>0</height>
            </size>
           </property>
          </widget>
         </item>
        </layout>
       </item>
      </layout>
     </widget>
    </item>
    <item row="2" column="0">
     <widget class="QTableView" name="tableView"/>
    </item>
   </layout>