엑셀( Excel ) 파일 생성 MFC API

Posted by 빵빵빵
2009/09/21 11:08 전산(컴퓨터)/PC-Windows




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

필요한 파일 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);



출처 : http://whiteat.com/zbxe/17858
2차출처 : http://yagi815.tistory.com/494
2009/09/21 11:08 2009/09/21 11:08

이 글에는 트랙백을 보낼 수 없습니다