728x90
반응형
-
벡터(vector)를 이용한 스프레드 쉬트 읽기는 고성능 처리를 제공합니다.
-
예제 코드 안에는 빠른 룩업, 자료 병합, 자료 중복 제거 등에 대한 더 많은 예제들이 있습니다.
#include <iostream>
#include <xlnt/xlnt.hpp>
#include <vector>
int main()
{
xlnt::workbook wb;
wb.load("/home/timothymccallum/test.xlsx");
auto ws = wb.active_sheet();
std::clog << "Processing spread sheet" << std::endl;
std::clog << "Creating a single vector which stores the whole spread sheet" << std::endl;
std::vector< std::vector<std::string> > theWholeSpreadSheet;
for (auto row : ws.rows(false))
{
std::clog << "Creating a fresh vector for just this row in the spread sheet" << std::endl;
std::vector<std::string> aSingleRow;
for (auto cell : row)
{
std::clog << "Adding this cell to the row" << std::endl;
aSingleRow.push_back(cell.to_string());
}
std::clog << "Adding this entire row to the vector which stores the whole spread sheet" << std::endl;
theWholeSpreadSheet.push_back(aSingleRow);
}
std::clog << "Processing complete" << std::endl;
std::clog << "Reading the vector and printing output to the screen" << std::endl;
for (int rowInt = 0; rowInt < theWholeSpreadSheet.size(); rowInt++)
{
for (int colInt = 0; colInt < theWholeSpreadSheet.at(rowInt).size(); colInt++)
{
std::cout << theWholeSpreadSheet.at(rowInt).at(colInt) << std::endl;
}
}
return 0;
}
- 상단 내용을 파일로 저장합니다.
/home/timothymccallum/process.cpp
- 다음과 같은 명령으로 컴파일합니다.
g++ -std=c++14 -lxlnt process.cpp -o process
- 다음과 같은 명령으로 에제를 실행합니다.
./process
프로그램의 출력값은 다음과 같을 것입니다.
Processing spread sheet
Creating a single vector which stores the whole spread sheet
Creating a fresh vector for just this row in the spread sheet
Adding this cell to the row
Adding this cell to the row
Adding this cell to the row
Adding this entire row to the vector which stores the whole spread sheet
Creating a fresh vector for just this row in the spread sheet
Adding this cell to the row
Adding this cell to the row
Adding this cell to the row
Adding this entire row to the vector which stores the whole spread sheet
Processing complete
Reading the vector and printing output to the screen
This is cell A1.
This is cell B1
… and this is cell C1
We are now on the second row at cell A2
B2
C2
- 이 프로세스가 매우 빨라서 성능을 측정하기가 어려울 것입니다. 그럴 경우 다음과 같이 “time”을 입력하면 얼마나 빨리 적재되고 스프레드 쉬트에 반영되는지 측정할 수 있습니다. 이 경우에는 아마도 일초도 걸리지 않을 것입니다.
time ./process
...
real 0m0.044s
- Xlnt (4) 값 쓰기 예제 http://j2doll.tistory.com/545
728x90
반응형
'C C++' 카테고리의 다른 글
GammaRay : Qt를 위한 Spy++ (0) | 2018.01.10 |
---|---|
Xlnt (4) 값 쓰기 예제 (0) | 2017.10.15 |
Xlnt (2) 입문 예제 : Hello, Xlnt !! (1) | 2017.10.15 |
Xlnt (1) 소개 : C++14 기반 excel(xlsx) 라이브러리 (0) | 2017.10.15 |
Qt single instance process (0) | 2017.09.08 |