代码文件

main
pjp8glqzm 7 months ago
parent 1a086321c1
commit 1a7db73ceb

@ -0,0 +1,46 @@
#ifndef EXCELREADER_H
#define EXCELREADER_H
#include <string>
#include <vector>
#include <xlnt/xlnt.hpp>
#include <libxls/xls.h> // 引入 libxls 库用于支持 .xls 格式
class ExcelReader {
public:
// 构造函数初始化Excel文件路径
ExcelReader(const std::string& fileName);
// 获取所有工作表的名称
std::vector<std::string> getSheetNames() const;
// 读取指定工作表的数据
std::vector<std::vector<std::string>> 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
Loading…
Cancel
Save