#include "ExportReportManager.h" #include "ProjectManager.h" #include #include #include #include #include #include ExportReportManager::ExportReportManager(QObject *parent) : QObject(parent) { m_word = new QWord(this); } ExportReportManager::~ExportReportManager() { delete m_word; } ProjectInfo *ExportReportManager::proj() const { return m_proj; } void ExportReportManager::setProj(ProjectInfo *proj) { m_proj = proj; } int ExportReportManager::evalType() const { return m_evalType; } void ExportReportManager::setEvalType(int type) { m_evalType = type; } bool ExportReportManager::exportReport() { bool createRet = createWord(); if (createRet == false) { qDebug() << __FUNCTION__ << __LINE__ << m_word->getStrErrorInfo() << endl; return false; } configWord(); addCover(); m_word->setVisible(true); m_word->saveAs(); m_word->close(); return true; } bool ExportReportManager::createWord() { // 报告文件夹路径 QString curPath = QDir::currentPath(); QString dateStr = QDate::currentDate().toString("yyyy-MM-dd"); QString reportDir = curPath + "/reports/" + dateStr + "/"; QDir dir(reportDir); if (!dir.exists()) { dir.mkpath(reportDir); } // 报告文件路径 QString typeStr = ProjectManager::nameOfEvalType((ProjectManager::EvalType)m_evalType); QString fileName = m_proj->projectName + "_" + typeStr + "报告.docx"; QString filePath = reportDir + fileName; qDebug() << __FUNCTION__ << __LINE__ << filePath << endl; // 创建 word 文档 return m_word->createNewWord(filePath); } void ExportReportManager::configWord() { m_word->setPageOrientation(0); m_word->setWordPageView(3); } void ExportReportManager::addCover() { m_word->setParagraphAlignment(0); //下面文字位置 m_word->setFontName(QString::fromLocal8Bit("黑体")); m_word->setFontSize(16); insertWraps(5); m_word->setFontSize(26); m_word->insertText(m_proj->projectName); QString typeStr = ProjectManager::nameOfEvalType((ProjectManager::EvalType)m_evalType); if (typeStr.length() > 2) { typeStr = typeStr.mid(0, typeStr.length() - 2); } m_word->insertText(typeStr); m_word->setFontSize(16); insertWraps(); m_word->setFontSize(26); m_word->insertText("评估报告"); m_word->setFontSize(16); insertWraps(10); m_word->setFontSize(18); m_word->insertText(m_proj->estimateDept); m_word->setFontSize(16); insertWraps(); m_word->setFontSize(18); m_word->insertText(QDate::currentDate().toString("yyyy年MM月")); m_word->setFontSize(16); insertWraps(2); } void ExportReportManager::insertWraps(int count) { for (int i = 0; i < count; ++i) { m_word->insertMoveDown(); } }