From 1a7db73ceb84c3fc7076dcba72c6c63a4e829ae3 Mon Sep 17 00:00:00 2001 From: pjp8glqzm <3795440669@qq.com> Date: Mon, 20 Jan 2025 18:17:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ExcelReader.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 ExcelReader.h diff --git a/ExcelReader.h b/ExcelReader.h new file mode 100644 index 0000000..70bd8e1 --- /dev/null +++ b/ExcelReader.h @@ -0,0 +1,46 @@ +#ifndef EXCELREADER_H +#define EXCELREADER_H + +#include +#include +#include +#include // 引入 libxls 库用于支持 .xls 格式 + +class ExcelReader { +public: + // 构造函数:初始化Excel文件路径 + ExcelReader(const std::string& fileName); + + // 获取所有工作表的名称 + std::vector getSheetNames() const; + + // 读取指定工作表的数据 + std::vector> readSheetData(const std::string& sheetName); + + // 获取指定工作表的单元格类型(文本、数字、日期等) + std::string getCellDataType(const std::string& sheetName, int row, int col); + + // 写入单元格数据 + void writeCellData(const std::string& sheetName, int row, int col, const std::string& value); + + // 保存Excel文件 + void saveToFile(const std::string& newFileName); + + // 设置单元格的数字格式 + void setCellNumberFormat(const std::string& sheetName, int row, int col, const std::string& format); + + // 合并单元格 + void mergeCells(const std::string& sheetName, int startRow, int startCol, int endRow, int endCol); + +private: + std::string fileName; + xlnt::workbook workbook; + // 用于标识文件类型 + bool isXlsx; + // 文件加载函数 + void loadFile(); + // 读取 .xls 文件 + void readXlsFile(); +}; + +#endif // EXCELREADER_H