메뉴 닫기

MFC 엑셀

2016. 11. 18. SincereGuy :: [MFC] 엑셀파일 읽기/쓰기 http://sincereguy.tistory.com/11 1/4 2016.11.18 검색 Total 17,035 Today 6 Yesterday 6 SincereGuy MediaLog Tag LocationLog Guestbook Admin Write [MFC] 엑셀파일 읽기/쓰기 Programing/MFC | 2011.02.27 18:52 Posted by SincereGuy MFC프로그램을 작성할때 외부파일 접근 필요시 보통 CFile클래스를 많이 이용한다. 하지만 CFile같은경우 txt파일정도는 읽기 편하지만 다른 응용프로그램파일과 연동은 힘들다. 처음 프로그램을 작성중 엑셀파일형식으로 데이터베이스가 저장되어 있을때 데이터베이스로 접근하기 위해 엑셀파일을 메모장에 복사하였다. 몇번을 그렇게 작업하던중 MFC에서 다이렉트로 엑셀파일로 접근하면 번거로움 없이 편하게 행열로 접근할 수 있을것 같았다. 그래서 CFile로 엑셀파일을 한번 열어보았는데, 양식이 달라서 제대로된 데이터 접근이 안되었다. visual studio와 엑셀이 같은 마이크로스프트 회사제품이니 서로 쉽게 연동되는줄 알았다. 찾아보니 ODBC로 어쩌구 저쩌구 설명되어 있던데 나같은 초보는 이해하기가 힘들었다. 이리저리 계속 찾아서 API를 구할 수 있었다. ExclAPI.zip 너무 이리저리 찾아서 출처를 모르겠다.ㅠ.ㅠㅋ 사용방법 먼저 위의 파일의 압축풀어 프로젝트에 추가를 시킨다. #include “XLEzAutomation.h”                            //<- 엑셀파일에 접근할 부분에 해더파일을 인크루드 해준다. char chThisPath[256]; CString strThisPath ; CXLEzAutomation dataexcel(FALSE);               // 엑셀클래스 선언 (FALSE: 처리 과정을 화면에 보이지 않는다) ///////////////////// 기본적으로 필요한 변수들 ///////////////////// GetCurrentDirectory(256, chThisPath);                                 //현재 디렉토리 위치를 구함 strThisPath.Format(“%s\\%s.xls”,chThisPath,”DataBase”); //디렉토리 위치에 엑셀파일을 지정  (ex)DataBase.xls GetModuleFileName( NULL, chThisPath, 256); //////////////////// 기본 세팅 ///////////////////// 여기까지 기본적으로 해주어야 할 상황이다. 열기, 읽기, 쓰기등 기본 함수를 알아보자. dataexcel.OpenExcelFile(strThisPath);        ///// 위에서 얻은 엑셀파일경로를 바탕으로 파일을 연다. dataexcel.SaveFileAs(strThisPath);            /////  변경된 엑셀파일을 저장한다. dataexcel.ReleaseExcel();                        /////  열었던 파일을 다 사용한 후 닫는다. CString dataexcel.GetCellValue( int 열번호 , int 행번호 );  //열번호와 행번호를 차래대로 전달하면 해당셀의 문자열을 리턴 dataexcel.SetCellValue( int 열번호 , int 행번호 , “저장할 문자열” );  // 위 행과는 반대되는 개념 위의 함수가 주로 사용하는 함수이다. (솔직히 말하면 내가 사용해본 함수^^;;;ㅋ)

40 Comments

  1. http://bit.ly/3drY6lE

    Cbd oil that works 2020
    I don’t know whether it’s just me or if everybody else encountering issues with
    your site. It appears as if some of the text in your posts are running off the screen.
    Can someone else please provide feedback and let me know if this is happening to them too?
    This could be a issue with my internet browser
    because I’ve had this happen previously. Thanks best cbd oil for pain http://bit.ly/3drY6lE cbd oil that works 2020 http://bit.ly/3drY6lE

  2. Lucio Dayhoff

    I just want to say I am just beginner to blogs and really liked you’re web blog. Very likely I’m want to bookmark your blog . You certainly have beneficial articles and reviews. Thanks a lot for sharing with us your website.

  3. buy viagra england

    Wonderful post. I find out something extra tough on various blog sites daily. It will always be boosting to check out content from other authors and exercise a little something from their store. I?d prefer to utilize some with the web content on my blog site whether you don?t mind. Natually I?ll offer you a link on your web blog. Thanks for sharing.

  4. security screens clarkson

    Have you ever considered about including a little bit more than just your articles? I mean, what you say is fundamental and everything. However just imagine if you added some great pictures or video clips to give your posts more, “pop”! Your content is excellent but with images and clips, this blog could definitely be one of the very best in its niche. Amazing blog!

  5. John Deere Repair Manuals

    *Youre so cool! I dont suppose Ive read anything like this before. So nice to find somebody with some original thoughts on this subject. realy thank you for starting this up. this website is something that is needed on the web, someone with a little originality. useful job for bringing something new to the internet!

  6. cbd treats for dogs portland

    Aw, this was a really nice article. In suggestion I wish to put in composing similar to this in addition? requiring time and real initiative to make a very good write-up? but what can I say? I postpone alot and also by no means appear to get something done.

  7. Home Page

    An excellent share, I just offered this onto an associate that was doing a little evaluation on this. As well as he as a matter of fact purchased me morning meal since I discovered it for him. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for investing the time to discuss this, I really feel strongly about it and love reading more on this subject. If possible, as you end up being proficiency, would you mind upgrading your blog site with more details? It is extremely practical for me. Big thumb up for this article!

  8. website hosting services

    Excellent blog! Do you have any tips and hints for aspiring writers?
    I’m hoping to start my own blog soon but I’m a little lost
    on everything. Would you suggest starting with a free platform like WordPress or go for a
    paid option? There are so many choices out there
    that I’m completely overwhelmed .. Any ideas?

    Kudos!

  9. check out this site

    Aw, this was an actually nice message. In concept I would love to put in writing such as this in addition? taking time as well as actual initiative to make a great article? however what can I say? I procrastinate alot and also by no means seem to get something done.

  10. Google

    Hi, I do believe this is an excellent web site. I stumbledupon it 😉 I may return once again since I book marked it. Money and freedom is the greatest way to change, may you be rich and continue to help others.

  11. Our site

    This is the appropriate blog site for anybody that wishes to find out about this subject. You realize so much its nearly hard to suggest with you (not that I really would want?HaHa). You most definitely put a new spin on a topic thats been written about for many years. Fantastic things, simply terrific!

  12. Google

    I was more than happy to find this website. I need to to thank you for your time due to this wonderful read!! I definitely appreciated every little bit of it and I have you bookmarked to look at new things in your site.

  13. website here

    The following time I check out a blog, I hope that it does not disappoint me as high as this one. I imply, I recognize it was my choice to check out, yet I really believed youd have something intriguing to state. All I hear is a bunch of whimpering concerning something that you could deal with if you werent also active looking for interest.

  14. adult phone chat line

    A person necessarily help to make critically posts I would state. This is the first time I frequented your web page and so far? I surprised with the analysis you made to make this particular publish amazing. Wonderful activity!

댓글 남기기

이메일은 공개되지 않습니다.