QWord.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef QWORD_H
  2. #define QWORD_H
  3. #include <QtGlobal>
  4. #ifdef Q_OS_WIN
  5. #define _WIN32_DCOM
  6. #include <QMainWindow>
  7. #include "qmainwindow.h"
  8. #include <QString>
  9. #include <QVariant>
  10. #include <ActiveQt/QAxObject>
  11. #include <ActiveQt/QAxWidget>
  12. #include "objbase.h"
  13. //#include "GlobalAppData.h"
  14. class QWord : public QObject
  15. {
  16. Q_OBJECT
  17. public:
  18. QWord(QObject *parent = 0);
  19. ~QWord();
  20. public:
  21. QAxObject *getDocuments() { return m_documents; }
  22. QAxObject *getDocument() { return m_document; }
  23. QAxObject *getWordApp() { return m_word; }
  24. public:
  25. /**************************************************************************/
  26. /* 文件 操作 */
  27. /**************************************************************************/
  28. void save(); //保存操作内容
  29. void close(); //关闭 退出 析构时候也会自动调用一次
  30. void saveAs(); //新建word另存为
  31. bool createWord(QString reportname); //创建一个新的word文档
  32. void openWord(); //打开一个现有的word文档
  33. bool createNewWord(const QString &filePath); //创建一个新的word文档
  34. void setTableAutoFitBehavior(int flag); //表格自动拉伸列: 0 固定 1根据内容调整 2 根据窗口调整
  35. void setPageOrientation(int flag); //设置页面0为纵向wdOrientPortrait 1为横向wdOrientLandscape
  36. void setWordPageView(
  37. int flag); //设置页面视图,是web视图wdWebView 6还是页面视图wdPrintView 3 或者阅读视图wdReadingView 7
  38. void setFontSize(int fontsize); //设置字体大小
  39. void setFontName(const QString &fontName); //设置字体 比如 “宋体”
  40. void setFontBold(bool flag); //字体加粗
  41. void setParagraphAlignment(int flag); //设置选中位置文字居左 0 ,居中 1 ,居右 2
  42. void setRowAlignment(int tableIndex, int row, int flag);
  43. //同时设置列宽和列高可以固定图片的大小
  44. void setColumnWidth(int column, int width); //设置列宽
  45. void setColumnHeight(int column, int height); //设置列高
  46. void setRowHeight(int nTable, int Row, int height);
  47. void setCellString(int row, int column, const QString &text);
  48. void setCellFontBold(int row, int column, bool isBold); //设置内容粗体 isBold控制是否粗体
  49. void setCellFontSize(int row, int column, int size); //设置文字大小
  50. void setOptionCheckSpell(bool flags); //设置审阅的拼写检查 true开启检查 false 取消检查
  51. QString GetText(); //获取内容
  52. void getUsedRange(int *topLeftRow, int *topLeftColumn, int *bottomRightRow, int *bottomRightColumn);
  53. void setSelectionRange(int start, int end); //"SetRange(1, 9)"第1个字符后开始,到第9个字符结束范围
  54. QVariant getCellValue(int row, int column); //获取单元格内容
  55. int getTableCount(); //获取word中表格总数
  56. QString getStrErrorInfo()
  57. {
  58. return m_strError;
  59. } //获取代码中出现的错误信息可以用QMessageBox::information打印 在cpp不用QMessageBox 是怕你们在线程中调导出报表
  60. void deleteSelectColumn(int column); //删除指定的列
  61. void moveForEnd(); //移动选定对象到文档末尾
  62. void insertCellPic(int row, int column, const QString &picPath); //单元格插入图片
  63. void intsertTable(int row, int column); //插入一个几行几列表格
  64. void insertMoveDown(); //插入回车
  65. void insertText(const QString &text); //插入文字
  66. void insertTable(int tableIndex, int row, int column);
  67. //插入巡检单位 巡检计划 巡检时间 巡 检 人 顺序传参
  68. // void insertTitle(const QString& str1,const QString& str2,const QString& str3,const QString& str4);
  69. void MergeCells(int tableIndex, int nStartRow, int nStartCol, int nEndRow, int nEndCol); //合并单元格
  70. bool open(const QString &strFilePath, bool bVisable);
  71. bool openword(bool bVisable);
  72. bool isOpen();
  73. void setColumnWidth(int nTable, int column, int width);
  74. void setCellString(int nTable, int row, int column, const QString &text);
  75. void insertCellPic(int nTable, int row, int column, const QString &picPath);
  76. void setCellFontBold(int nTable, int row, int column, bool isBold);
  77. void setCellFontSize(int nTable, int row, int column, int size);
  78. // void addTableRow(int nTable ,int nRow,int rowCount);
  79. void addTableRow(int tableIndex, int nRow, int rowCount);
  80. void setColumnHeight(int nTable, int column, int height);
  81. void intsertTable(int tableIndex, int row, int column);
  82. public:
  83. void setVisible(bool isVisible);
  84. private:
  85. QAxObject *m_word;
  86. QAxObject *m_documents;
  87. QAxObject *m_document;
  88. QString m_fileName;
  89. QString m_saveName;
  90. QString m_strError;
  91. QString m_strFilePath;
  92. bool m_bOpened;
  93. };
  94. #endif
  95. #endif // QWORD_H