메뉴 바로가기

서브메뉴 바로가기

본문 바로가기

logo

C/C++/MFC

2011년 01월 07월에 새로운 엑셀관련 라이브러리가 나왔습니다.

무지 편해진거 같네요.

 http://www.codeproject.com/KB/office/ExcelFormat.aspx

 

 

 

 

============================================================================

http://www.codeguru.com/cpp/data/mfc_database/microsoftexcel/article.php/c11745/ 의 내용에서 필요한 부분만 골랐습니다.

 

전체소스 : WATExcelRW_src.zip

실행파일 : WATExcelRW_exe.zip


필요한 파일 4개이다.
    XLEzAutomation.h
    XLEzAutomation.cpp
    XLAutomation.h
    XLAutomation.cpp

함수를 구현할 파일에 한 줄을 추가한다
    #include "XLEzAutomation.h"


엑셀 파일 기록하기(파일이 존재하지 않을 경우 새로운 파일이 생성된다.)
 

 void CWATExcelRWDlg::OnBnClickedButton1()
{
 char chThisPath[_MAX_PATH];
 GetCurrentDirectory( _MAX_PATH, chThisPath);
 
 UpdateData(TRUE);
 CString strThisPath ;
 strThisPath.Format("%s\\%s.xls",chThisPath,m_strFileName);

 CXLEzAutomation XL(FALSE); // FALSE: 처리 과정을 화면에 보이지 않는다


  XL.SetCellValue(1,1,"ddd");
 XL.SetCellValue(1,2,"22");
  XL.SetCellValue(4,4,"4,4");
  XL.SetCellValue(7,4,"7,4");
 XL.SaveFileAs(strThisPath);

 XL.ReleaseExcel();
}


엑셀파일 읽어오기

 

  char chThisPath[_MAX_PATH];
 GetCurrentDirectory( _MAX_PATH, chThisPath);

 UpdateData(TRUE);
 CString strThisPath ;
 CString strData;
 strThisPath.Format("%s\\%s.xls",chThisPath,m_strFileName);

 GetModuleFileName( NULL, chThisPath, _MAX_PATH);

 CXLEzAutomation XL(FALSE); // FALSE: 처리 과정을 화면에 보이지 않는다

 XL.OpenExcelFile(strThisPath);
 strData +="\n(1,1) = ";
 strData +=XL.GetCellValue(1,1);
 strData +="\n(1,2) = ";
 strData +=XL.GetCellValue(1,2);
 strData +="\n(1,3) = ";
 strData +=XL.GetCellValue(1,3);
 strData +="\n(1,4) = ";
 strData +=XL.GetCellValue(1,4);

 strData +="\n(4,4) = ";
 strData +=XL.GetCellValue(4,4);

 strData +="\n(7,4) = ";
 strData +=XL.GetCellValue(7,4);

 XL.ReleaseExcel();
 MessageBox(strData);

 

 

 

 

관련 문서가 검색되었습니다.
  1. [2011/04/21] 엑셀 문자열 기준으로 순위 변동 표시하기 by WhiteAT (8451)