123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- #include "ExportReportManager.h"
- #include "ProjectManager.h"
- #include <dbService/ClassSet.h>
- #include <QWord/QWord.h>
- #include <QWord/QWordDemo.h>
- #include <QDir>
- #include <QDate>
- #include <QDebug>
- 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();
- }
- }
|