-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeProject1.cpp
More file actions
37 lines (31 loc) · 899 Bytes
/
Copy pathCMakeProject1.cpp
File metadata and controls
37 lines (31 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <OpenXLSX.hpp>
#include <iostream>
#include <locale>
#include <codecvt>
using namespace std;
using namespace OpenXLSX;
int main() {
// 设置控制台为 UTF-8 编码(仅适用于 Windows)
#ifdef _WIN32
system("chcp 65001");
#endif
try {
XLDocument doc;
doc.open("../../../aa.xlsx"); // 假设 Excel 文件是 students.xlsx
auto wks = doc.workbook().worksheet("Sheet1");
for (auto row : wks.rows()) {
for (auto cell : row.cells()) {
// 将 OpenXLSX 的 XLString 转换为 std::string
std::string value = cell.value().get<std::string>();
cout << value << " ";
}
cout << endl;
}
doc.close();
}
catch (const std::exception& e) {
cout << "Error opening file: " << e.what() << endl;
return 1;
}
return 0;
}