#pragma once // Excel 读取库 #if defined(_MSC_VER) || defined(WIN64) || defined(__WIN64__) || defined(WIN32) || defined(_WIN32) #ifdef _OCC_P_EXCLETOOL_SDK #define _OCC_P_EXCLETOOL_API __declspec(dllexport) #else #define _OCC_P_EXCLETOOL_API __declspec(dllimport) #endif #else //linux #ifdef _OCC_P_EXCLETOOL_SDK #define _OCC_P_EXCLETOOL_API __attribute__ ((visibility("default"))) #else #define _OCC_P_EXCLETOOL_API __attribute__ ((visibility("default"))) #endif #endif // WIN64||WIN32 #include #include class xhExcelReader; class xhExcelWriter; class _OCC_P_EXCLETOOL_API YD_ExcelReader { public: YD_ExcelReader(void); ~YD_ExcelReader(void); enum ex_ret_code { cd_gbk, cd_utf8, cd_auto //windows 下返回GBK ,linux 下返回utf8 }; public: int GetSheelNames(const std::string& strFileName, std::vector& vrSheetList); //加载 Excel 使用表格名称 int LoadSheet(const std::string& strFileName,const std::string & strSheetName); //加载 Excel 使用表格编号,编号从0开始 int LoadSheet(const std::string& strFileName, int nSheetIndex); //获取列名 列名为Excel第一行 int GetColNameList(std::vector & vrStringList); //获取列数 int GetColCount(); //获取行数 int GetRowCount(); //获取Excel单元格 根据列名获取 std::string FieldByName_AsString(const std::string& strFieldName,int nRow); int FieldByName_AsInt(const std::string& strFieldName, int nRow); double FieldByName_AsFloat(const std::string& strFieldName, int nRow); //获取Excel单元格 根据列编号获取 std::string Cell_AsString(int nRow,int nCol); int Cell_AsInt(int nRow, int nCol); double Cell_AsFloat(int nRow, int nCol); void SetReturnCode(ex_ret_code code); ex_ret_code GetReturnCode(); private: xhExcelReader * m_preader; }; class _OCC_P_EXCLETOOL_API YD_ExcelWriter { public: YD_ExcelWriter(void); ~YD_ExcelWriter(void); public: //打开Excel文件 不存在就创建 int OpenFile(const std::string& strFileName,bool isCreateNew = false); //打开Sheet 不存在就创建 int OpenSheet(const std::string& strSheetName); //写入值 int WriteStr(int nRow, int nCol,const std::string & strValue); int writeNum(int nRow, int nCol, double dValue); //关闭 int Close(); private: xhExcelWriter* m_pWriter; };