Ulricy před 1 rokem
rodič
revize
b961a295f1

+ 86 - 4
QFD/common/ExportReportManager.cpp

@@ -54,7 +54,9 @@ bool ExportReportManager::exportReport()
 
     insertCommonInfo();
     if (m_evalType == ProjectManager::OptimalEval) {
-        insertSchemeInfo();
+        insertSchemeDesignInfo();
+        insertSchemeIndex();
+        insertSchemeData();
     }
 
     m_word->setVisible(true);
@@ -110,7 +112,7 @@ void ExportReportManager::insertCommonInfo()
     insertText("bmEvalPurpose", m_proj->estimateObjective);
 }
 
-void ExportReportManager::insertSchemeInfo()
+void ExportReportManager::insertSchemeDesignInfo()
 {
     QList<SchemaEval *> schemeList;
     bool ret = SchemeInfoService().QuerySchemeInfoByEngineerId(&schemeList, m_proj->id, 0);
@@ -160,11 +162,34 @@ void ExportReportManager::insertSchemeInfo()
     }
 }
 
+void ExportReportManager::insertSchemeIndex()
+{
+    insertText("bmProjName31", m_proj->projectName);
+    insertText("bmProjName32", m_proj->projectName);
+
+    //    bmIndexTable
+    QAxObject *table = insertTable("bmIndexTable", 15, 5);
+    if (table == nullptr) {
+        return;
+    }
+
+    m_word->setFontName(QString::fromLocal8Bit("仿宋_GB2312"));
+    m_word->setFontSize(9);
+    m_word->setParagraphAlignment(0);
+    setCellString(table, 1, 1, "index");
+    mergeCells(table, 1, 1, 2, 2);
+    setCellString(table, 3, 1, "index2");
+}
+
+void ExportReportManager::insertSchemeData()
+{
+    insertText("bmProjName41", m_proj->projectName);
+}
+
 bool ExportReportManager::insertText(const QString &bookmark, const QString &text)
 {
     bool ret              = false;
-    QAxObject *doc        = m_word->getWordApp()->querySubObject("ActiveDocument");
-    QAxObject *bmProjName = doc->querySubObject("Bookmarks(QVariant)", bookmark);
+    QAxObject *bmProjName = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", bookmark);
 
     if (bmProjName != nullptr) {
         bmProjName->dynamicCall("Select(void)");
@@ -173,3 +198,60 @@ bool ExportReportManager::insertText(const QString &bookmark, const QString &tex
     }
     return ret;
 }
+
+QAxObject *ExportReportManager::insertTable(QString bookmark, int row, int column)
+{
+    QAxObject *bmTable = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", bookmark);
+    if (bmTable) {
+        bmTable->dynamicCall("Select(void)");
+        QAxObject *selection = m_word->getWordApp()->querySubObject("Selection");
+        if (!selection)
+            return nullptr;
+
+        selection->dynamicCall("InsertAfter(QString&)", "\n");
+        // selection->dynamicCall("MoveLeft(int)", 1);
+        selection->querySubObject("ParagraphFormat")->dynamicCall("Alignment", "wdAlignParagraphCenter");
+        //        selection->dynamicCall("TypeText(QString&)", "Table Test");  //设置标题
+
+        QAxObject *range  = selection->querySubObject("Range");
+        QAxObject *tables = m_word->getDocument()->querySubObject("Tables");
+        QAxObject *table  = tables->querySubObject("Add(QVariant,int,int)", range->asVariant(), row, column);
+        if (!tables)
+            return nullptr;
+
+        for (int i = 1; i <= 6; i++) {
+            QString str        = QString("Borders(-%1)").arg(i);
+            QAxObject *borders = table->querySubObject(str.toLocal8Bit().constData());
+            borders->dynamicCall("SetLineStyle(int)", 1);
+        }
+        return table;
+    }
+
+    return nullptr;
+}
+
+void ExportReportManager::setCellString(QAxObject *table, int row, int column, const QString &text)
+{
+    if (table == nullptr) {
+        return;
+    }
+    table->querySubObject("Cell(int,int)", row, column)->querySubObject("Range")->dynamicCall("SetText(QString)", text);
+}
+
+void ExportReportManager::mergeCells(QAxObject *table, int row, int column, int rowSpan, int columnSpan)
+{
+    if (table == nullptr) {
+        return;
+    }
+
+    QAxObject *startCell = table->querySubObject("Cell(int, int)", row, column);
+    QAxObject *endCell   = table->querySubObject("Cell(int, int)", row + rowSpan - 1, column + columnSpan - 1);
+    if (nullptr == startCell) {
+        return;
+    }
+    if (nullptr == endCell) {
+        return;
+    }
+
+    startCell->querySubObject("Merge(LPDISPATCH)", endCell->asVariant());
+}

+ 21 - 3
QFD/common/ExportReportManager.h

@@ -6,6 +6,7 @@
 class ProjectInfo;
 
 class QWord;
+class QAxObject;
 
 class ExportReportManager : public QObject
 {
@@ -29,12 +30,21 @@ private:
     // 插入不同评估类型下共同的信息
     void insertCommonInfo();
 
-    // 填充方案信息
-    void insertSchemeInfo();
+    // 填充方案评估方案设计信息
+    void insertSchemeDesignInfo();
+    // 填充方案评估指标信息
+    void insertSchemeIndex();
+    // 填充方案数据
+    void insertSchemeData();
 
     // 在一个书签位置插入文字
     bool insertText(const QString &bookmark, const QString &text);
 
+    // 在一个标签位置插入表格
+    QAxObject *insertTable(QString bookmark, int row, int column);
+    void setCellString(QAxObject *table, int row, int column, const QString &text);
+    void mergeCells(QAxObject *table, int row, int column, int rowSpan, int columnSpan);
+
 signals:
 
 private:
@@ -65,7 +75,7 @@ private:
 */
 
 /**
- * 标签名称
+ * 方案优选评估标签名称
  *
  * 封面
  * 项目名称:bmProjName,单位:bmProjUnit,时间:bmProjDate
@@ -76,6 +86,14 @@ private:
  * 方案设计
  * 方案描述:bmSchemes
  *
+ * 评估指标管理
+ * 描述项目名称:bmProjName31
+ * 表格项目名称:bmProjName32
+ * 表格:bmIndexTable
+ *
+ * 方案数据设置
+ * 表格项目名称:bmProjName41
+ *
  * 2023-12-13 by chengxr
  */
 

+ 0 - 1
QFD/helper/QWord/QWord.cpp

@@ -679,7 +679,6 @@ void QWord::addTableRow(int tableIndex, int nRow, int rowCount)
 ////创建表格
 void QWord::insertTable(int tableIndex, int row, int column)
 {
-    qDebug() << __FUNCTION__ << __LINE__ << m_document << endl;
     QAxObject *tables = m_document->querySubObject("Tables");
     if (nullptr == tables) {
         return;