DSCAnalysisTool/src/data/xlsxhandler.cpp

72 lines
2.2 KiB
C++
Raw Normal View History

2025-04-12 13:02:37 +00:00
#include "xlsxhandler.h"
#include "global.h"
#include "logger.h"
void XlsxHandler::test()
{
QString sourceFilePath = QDir::currentPath() + "/sample.xlsx";
qDebug()<<"fileName:"<<sourceFilePath;
readFile(sourceFilePath);
}
void XlsxHandler::readFile(const QString sourceFilePath)
{
// 检查文件是否存在
if (!QFile::exists(sourceFilePath)) {
qDebug() << "文件不存在:" << sourceFilePath;
return ;
}
// 尝试打开文件
QXlsx::Document xlsx(sourceFilePath);
#if 0
// 获取所有工作表名称
QStringList sheetNames = xlsx.sheetNames();
qDebug() << "工作表名称:" << sheetNames;
#endif
QXlsx::Worksheet *workSheet = xlsx.currentWorksheet();
if (!workSheet) {
qDebug() << "当前工作表为空。";
return;
}
// 获取工作表的行数和列数
int rowCount = workSheet->dimension().rowCount();
int colCount = workSheet->dimension().columnCount();
qDebug() << "row:" << rowCount << "col:" << colCount;
logde<<"0:"<<workSheet->cellAt(1, 1)->value().toString().toStdString();
qDebug()<<workSheet->cellAt(1, 1)->value().toString();
int index = 2;
Global::ExperimentInfo ei;
ei.sampleName = workSheet->cellAt(index++, 2)->value().toString();
logde<<"sample name:"<<ei.sampleName.toStdString();
// return;
ei.sampleWeight = workSheet->cellAt(index++, 2)->value().toString();
ei.date = workSheet->cellAt(index++, 2)->value().toString();
ei.operatorName = workSheet->cellAt(index++, 2)->value().toString();
ei.phaseSize = workSheet->cellAt(index++, 2)->value().toInt();
2025-04-13 08:15:54 +00:00
QVector<PhaseTotalInfo> phaseTotalVtr;
2025-04-12 13:02:37 +00:00
for(int i = 0;i < ei.phaseSize;i++){
2025-04-13 08:15:54 +00:00
PhaseTotalInfo phaseTotoal;
readPhaseData(workSheet,phaseTotoal);
phaseTotalVtr.push_back(phaseTotoal);
2025-04-12 13:02:37 +00:00
}
}
2025-04-13 08:15:54 +00:00
void XlsxHandler::readPhaseData(QXlsx::Worksheet *workSheet,const int index, PhaseTotalInfo &phase)
2025-04-12 13:02:37 +00:00
{
const int startIndex = 9;
#if 0
int index = startIndex;
phase.phaseName = workSheet->cellAt(index++, 2)->value().toString();
phase.phaseWeight = workSheet->cellAt(index++, 2)->value().toString();
#endif
}