You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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