2025-04-13T18:10:29
This commit is contained in:
parent
dc94e00d88
commit
ecec86e4fd
@ -1,5 +1,4 @@
|
|||||||
#include "xlsxhandler.h"
|
#include "xlsxhandler.h"
|
||||||
#include "global.h"
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
void XlsxHandler::test()
|
void XlsxHandler::test()
|
||||||
@ -11,7 +10,8 @@ void XlsxHandler::test()
|
|||||||
void XlsxHandler::readFile(const QString sourceFilePath)
|
void XlsxHandler::readFile(const QString sourceFilePath)
|
||||||
{
|
{
|
||||||
// 检查文件是否存在
|
// 检查文件是否存在
|
||||||
if (!QFile::exists(sourceFilePath)) {
|
if(!QFile::exists(sourceFilePath))
|
||||||
|
{
|
||||||
qDebug() << "文件不存在:" << sourceFilePath;
|
qDebug() << "文件不存在:" << sourceFilePath;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -26,7 +26,8 @@ void XlsxHandler::readFile(const QString sourceFilePath)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
QXlsx::Worksheet *workSheet = xlsx.currentWorksheet();
|
QXlsx::Worksheet *workSheet = xlsx.currentWorksheet();
|
||||||
if (!workSheet) {
|
if(!workSheet)
|
||||||
|
{
|
||||||
qDebug() << "当前工作表为空。";
|
qDebug() << "当前工作表为空。";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -51,21 +52,73 @@ void XlsxHandler::readFile(const QString sourceFilePath)
|
|||||||
ei.operatorName = workSheet->cellAt(index++, 2)->value().toString();
|
ei.operatorName = workSheet->cellAt(index++, 2)->value().toString();
|
||||||
ei.phaseSize = workSheet->cellAt(index++, 2)->value().toInt();
|
ei.phaseSize = workSheet->cellAt(index++, 2)->value().toInt();
|
||||||
|
|
||||||
QVector<PhaseTotalInfo> phaseTotalVtr;
|
QVector<Global::PhaseTotalInfo> phaseTotalVtr;
|
||||||
for(int i = 0;i < ei.phaseSize;i++){
|
int startLineIndex = 9;
|
||||||
PhaseTotalInfo phaseTotoal;
|
for(int i = 0; i < ei.phaseSize; i++)
|
||||||
readPhaseData(workSheet,phaseTotoal);
|
|
||||||
phaseTotalVtr.push_back(phaseTotoal);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void XlsxHandler::readPhaseData(QXlsx::Worksheet *workSheet,const int index, PhaseTotalInfo &phase)
|
|
||||||
{
|
{
|
||||||
const int startIndex = 9;
|
Global::PhaseTotalInfo phaseTotal;
|
||||||
|
phaseTotal.phaseIndex = i + 1;
|
||||||
|
|
||||||
|
readPhaseData(workSheet, startLineIndex, phaseTotal);
|
||||||
|
phaseTotalVtr.push_back(phaseTotal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void XlsxHandler::readPhaseData(QXlsx::Worksheet *workSheet, int &startLineIndex,
|
||||||
|
Global::PhaseTotalInfo &phaseTotal)
|
||||||
|
{
|
||||||
|
// int startLineIndex = 9;
|
||||||
|
startLineIndex++;
|
||||||
|
startLineIndex++;
|
||||||
|
|
||||||
|
phaseTotal.phase.cutoff_temp = workSheet->cellAt(startLineIndex++, 2)->value().toFloat();
|
||||||
|
phaseTotal.phase.temp_flow = workSheet->cellAt(startLineIndex++, 2)->value().toFloat();
|
||||||
|
phaseTotal.phase.constant_temp_time_min = (uint16_t)(workSheet->cellAt(startLineIndex++, 2)->value().toInt());
|
||||||
|
phaseTotal.phase.gas = static_cast<GasType>(workSheet->cellAt(startLineIndex++, 2)->value().toInt());
|
||||||
|
|
||||||
|
int dataSize = workSheet->cellAt(startLineIndex++, 2)->value().toInt();
|
||||||
|
for(int i = 0; i < dataSize; i++)
|
||||||
|
{
|
||||||
|
Global::ExperimentData data;
|
||||||
|
data.runTime = workSheet->cellAt(startLineIndex++, 2)->value().toFloat();
|
||||||
|
data.sampleTemp = workSheet->cellAt(startLineIndex++, 3)->value().toFloat();
|
||||||
|
data.dsc = workSheet->cellAt(startLineIndex++, 4)->value().toFloat();
|
||||||
|
|
||||||
|
phaseTotal.dataVtr.push_back(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void XlsxHandler::writeFile()
|
||||||
|
{
|
||||||
|
QXlsx::Document xlsx;
|
||||||
|
xlsx.addSheet("Sheet1"); // 添加一个新的工作表
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
int index = startIndex;
|
// 创建一个新的 Excel 文档
|
||||||
phase.phaseName = workSheet->cellAt(index++, 2)->value().toString();
|
QXlsx::Document xlsx;
|
||||||
phase.phaseWeight = workSheet->cellAt(index++, 2)->value().toString();
|
|
||||||
|
// 检查数据是否为空
|
||||||
|
if (data.isEmpty()) {
|
||||||
|
qWarning() << "没有数据可写入";
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 遍历数据并写入单元格
|
||||||
|
for (int row = 0; row < data.size(); ++row) {
|
||||||
|
const QVector<QString>& rowData = data[row];
|
||||||
|
for (int col = 0; col < rowData.size(); ++col) {
|
||||||
|
QString cellValue = rowData[col];
|
||||||
|
xlsx.write(row + 1, col + 1, cellValue); // 行和列从1开始
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存文件
|
||||||
|
if (!xlsx.saveAs(filePath)) {
|
||||||
|
qWarning() << "无法保存文件:" << filePath;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "文件保存成功:" << filePath;
|
||||||
|
return ;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,11 +5,14 @@
|
|||||||
|
|
||||||
#include "xlsxdocument.h"
|
#include "xlsxdocument.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
namespace XlsxHandler {
|
namespace XlsxHandler {
|
||||||
void test();
|
void test();
|
||||||
void readFile(const QString filePath);
|
void readFile(const QString filePath);
|
||||||
void readPhaseData(QXlsx::Worksheet*,const int index,PhaseTotalInfo&);
|
void readPhaseData(QXlsx::Worksheet*,int& startLineIndex,Global::PhaseTotalInfo&);
|
||||||
|
|
||||||
|
void writeFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // XLSX_H
|
#endif // XLSX_H
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#include <qfile.h>
|
#include <qfile.h>
|
||||||
#include <qcustomplot.h>
|
#include <qcustomplot.h>
|
||||||
|
|
||||||
//#include "filemanager.h"
|
#include "protocol.h"
|
||||||
|
|
||||||
class Global:public QObject
|
class Global:public QObject
|
||||||
{
|
{
|
||||||
@ -35,6 +35,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct ExperimentData {
|
struct ExperimentData {
|
||||||
|
float runTime;
|
||||||
float sampleTemp;
|
float sampleTemp;
|
||||||
float dsc;
|
float dsc;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user