2025-06-23 10:41:33 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "xlnt/xlnt.hpp"
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QList>
|
|
|
|
|
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//excel文件操作类
|
2025-06-23 10:41:33 +08:00
|
|
|
|
class ExcelOP
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ExcelOP();
|
|
|
|
|
~ExcelOP();
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//打开
|
2025-06-23 10:41:33 +08:00
|
|
|
|
bool OpenFile(QString& filePath);
|
|
|
|
|
void saveFile(QString& filePath);
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//读指定sheet页数据
|
2025-06-23 10:41:33 +08:00
|
|
|
|
bool readSheetData(QString name, QList<QStringList>& result, bool& hasEmptyCell);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//写指定sheet页数据,没有sheet页则新建
|
2025-06-23 10:41:33 +08:00
|
|
|
|
void writeSheetData(QString name, QList<QStringList>& input);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//删除所有sheet
|
2025-06-23 10:41:33 +08:00
|
|
|
|
void clearAllSheet();
|
2025-06-23 18:01:09 +08:00
|
|
|
|
// //新建sheet页
|
2025-06-23 10:41:33 +08:00
|
|
|
|
// void addSheet(QString name);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
// //设置当前的sheet页
|
2025-06-23 10:41:33 +08:00
|
|
|
|
// void getSheetByName(QString name);
|
|
|
|
|
// void getSheetById(int id);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
// //设置表头
|
2025-06-23 10:41:33 +08:00
|
|
|
|
// void setSheetHead(std::string headName[]);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//整行批量写入
|
2025-06-23 10:41:33 +08:00
|
|
|
|
// void setRowValue(int rowId, const QStringList& rowValue);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
// //设置指定单元格
|
2025-06-23 10:41:33 +08:00
|
|
|
|
// void setCell(int x, int y, std::string strValue);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
// //读出所有数据
|
2025-06-23 10:41:33 +08:00
|
|
|
|
// void readAllData(QList<QStringList>& rowVlaue);
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
// //读出指定行数据
|
2025-06-23 10:41:33 +08:00
|
|
|
|
// void readRowValue(int y, QStringList& valuelist);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
// //读某指定单元格
|
2025-06-23 10:41:33 +08:00
|
|
|
|
// std::string readCell(int x, int y);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
// //获取总行数
|
2025-06-23 10:41:33 +08:00
|
|
|
|
// int totalRows();
|
2025-06-23 18:01:09 +08:00
|
|
|
|
// //获取总列数
|
2025-06-23 10:41:33 +08:00
|
|
|
|
// int totalColumns();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
xlnt::workbook wb;
|
2025-06-23 18:01:09 +08:00
|
|
|
|
xlnt::worksheet currentSheet; //当前操作的sheet页
|
2025-06-23 10:41:33 +08:00
|
|
|
|
};
|
|
|
|
|
|