QT读取两份excel的坐标信息并计算平均误差的工程
时间: 2024-03-20 11:40:40 浏览: 57
您好,您可以使用Qt自带的QAxObject来读取Excel文件,以下是一个简单的示例代码:
```cpp
QAxObject* excel = new QAxObject("Excel.Application");
QAxObject* workbooks = excel->querySubObject("Workbooks");
QAxObject* workbook1 = workbooks->querySubObject("Open(const QString&)", "file1.xlsx");
QAxObject* workbook2 = workbooks->querySubObject("Open(const QString&)", "file2.xlsx");
QAxObject* sheets1 = workbook1->querySubObject("Worksheets");
QAxObject* sheets2 = workbook2->querySubObject("Worksheets");
QAxObject* sheet1 = sheets1->querySubObject("Item(int)", 1); // 第1个工作表
QAxObject* sheet2 = sheets2->querySubObject("Item(int)", 1); // 第1个工作表
QAxObject* usedrange1 = sheet1->querySubObject("UsedRange");
QAxObject* usedrange2 = sheet2->querySubObject("UsedRange");
int rowcount1 = usedrange1->property("Rows").toInt(); // 行数
int rowcount2 = usedrange2->property("Rows").toInt(); // 行数
int colcount1 = usedrange1->property("Columns").toInt(); // 列数
int colcount2 = usedrange2->property("Columns").toInt(); // 列数
for (int i = 1; i <= rowcount1; i++) {
for (int j = 1; j <= colcount1; j++) {
QAxObject* cell1 = sheet1->querySubObject("Cells(int,int)", i, j);
QVariant value1 = cell1->property("Value");
// 处理第1个Excel文件的坐标信息
// ...
cell1->clear();
delete cell1;
}
}
for (int i = 1; i <= rowcount2; i++) {
for (int j = 1; j <= colcount2; j++) {
QAxObject* cell2 = sheet2->querySubObject("Cells(int,int)", i, j);
QVariant value2 = cell2->property("Value");
// 处理第2个Excel文件的坐标信息
// ...
cell2->clear();
delete cell2;
}
}
usedrange1->dynamicCall("ClearContents()");
usedrange2->dynamicCall("ClearContents()");
delete usedrange1;
delete usedrange2;
delete sheet1;
delete sheet2;
workbook1->dynamicCall("Close()");
workbook2->dynamicCall("Close()");
delete workbook1;
delete workbook2;
delete sheets1;
delete sheets2;
workbooks->dynamicCall("Close()");
delete workbooks;
excel->dynamicCall("Quit()");
delete excel;
```
对于计算坐标信息的问题,您需要进一步说明,比如坐标数据的格式,需要计算的误差定义等。
阅读全文