반응형

간단한 예제 - 기존의 xlsx 스프레드 쉬트파일에서 읽기

  • 다음의 C++ 코드는 xlsx 파일로 부터 값을 읽고 값을 화면으로 출력하는 예제입니다. 이 예제는 시작하는 이들에게 매우 쉬운 예제가 될 것입니다.
#include <iostream>
#include <xlnt/xlnt.hpp>

int main() 
{
  xlnt::workbook wb;
  wb.load("/home/timothymccallum/test.xlsx");
  auto ws = wb.active_sheet();
  std::clog << "Processing spread sheet" << std::endl;     
  for (auto row : ws.rows(false)) {         
    for (auto cell : row) {    
      std::clog << cell.to_string() << std::endl; 
    }     
  }
  std::clog << "Processing complete" << std::endl;     
  return 0; 
}
  • 위의 내용을 다음과 같이 저장하세요.
/home/timothymccallum/process.cpp
  • 다음과 같은 명령을 입력하여 컴파일하십시오.
g++ -std=c++14 -lxlnt process.cpp -o process
  • 다음과 같은 명령을 입력하여 실행하십시오.
./process
  • 프로그램의 결과는 다음과 같을 것입니다.
Processing spread sheet
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
Processing complete
  • process.cpp 파일을 보시는 바와 같이 스프레드 쉬트의 값들의 열단위 행단위로 진행합니다.

다음글

728x90
반응형

'C C++' 카테고리의 다른 글

Xlnt (4) 값 쓰기 예제  (0) 2017.10.15
Xlnt (3) Vector를 이용한 예제  (0) 2017.10.15
Xlnt (1) 소개 : C++14 기반 excel(xlsx) 라이브러리  (0) 2017.10.15
Qt single instance process  (0) 2017.09.08
Determining 32 vs 64 bit in C++  (0) 2017.09.07

+ Recent posts