我的测试版本Qt 5.6.2    QtCreator4.0.3    VS2013

qtExcelApi.h

  1 #pragma once
  2 
  3 #include <ActiveQt/QAxObject>
  4 #include <QDir>
  5 
  6 using namespace std;
  7 
  8 class qtExcelApi
  9 {
 10 public:
 11     qtExcelApi(void);
 12     ~qtExcelApi(void);
 13 
 14 
 15     /**
 16     * @brief 新建Excel
 17     */
 18     void CreateExcel();
 19 
 20 
 21     /**
 22     * @brief 打开Excel
 23     * @param[in] filePath  路径
 24     * @param[in] type  打开时是否显示EXCEL
 25     * @return BOOL 打开成功&失败
 26     */
 27     bool OpenFile(const char* filePath, bool type);
 28 
 29 
 30     /**
 31     * @brief 关闭Excel
 32     */
 33     void CloseExcel();
 34 
 35 
 36     /**
 37     * @brief 保存Excel
 38     */
 39     void Save(const char* savePath);
 40 
 41 
 42     /**
 43     * @brief 获取所有的工作表数量
 44     * @return int 数量
 45     */
 46     int GetSheetCount();
 47 
 48 
 49     /**
 50     * @brief 获取单元格数据
 51     * @param[in] row  行
 52     * @param[in] column  列
 53     * @return string 内容
 54     */
 55     string GetRangeData(const int row, const int column);
 56 
 57 
 58     /**
 59     * @brief 读取整个sheet
 60     * @return string 内容
 61     */
 62     vector<string> GetUsedRange();
 63 
 64 
 65     /**
 66     * @brief 读取sheet中的一个范围
 67     * @return string 内容
 68     */
 69     vector<string> GetScopeRange(const char* A1, const char* A5);
 70     
 71 
 72     /**
 73     * @brief 当前sheet单元格写入内容
 74     * @param[in] row  行
 75     * @param[in] column  列
 76     * @param[in] Data  内容
 77     */
 78     void SetRangeData(const int row, const int column, const char* Data);
 79 
 80 
 81     /**
 82     * @brief 获得当前sheet使用的行数
 83     * @return int 数量
 84     */
 85     int GetRowNum();
 86 
 87 
 88     /**
 89     * @brief 获得当前sheet使用的列数
 90     * @return int 数量
 91     */
 92     int GetColumnNum();
 93 
 94 
 95     /**
 96     * @brief 设置当前工作表
 97     * @param[in] id  第几个sheet,从1开始
 98     * @return BOOL 设置成功&失败
 99     */
100     bool SetCurrentSheetByNum(const int& id);
101 
102 
103 
104 private:
105 
106     //Excel应用程序
107     QAxObject *ExcelApp;
108     //Excel工作簿
109     QAxObject *ExcelBooks;
110     QAxObject *ExcelBook;
111     //Excel工作表
112     QAxObject *ExcelSheets;
113     QAxObject *ExcelSheet;
114     //Excel单元格
115     QAxObject *ExcelRange;
116 
117 };
View Code

相关文章: