C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[13494] Re:[질문]Excel파일 레코드 읽기
건전맨 [hoonlim] 1613 읽음    2001-12-09 17:01
while 문으로 돌려보세요..
제가 한 것데 가져오는 것은 되거든요..
저는 엑셀 파일을 불러와서 테이블에 넣고 다시 테이블을 가져옵니다.
조언이 될지 모르겠습니다.

    // 셀로 작업할 경우
    Variant VCell;
    AnsiString val1, val2, val3;
    VCell = xlSheet.OlePropertyGet("Cells", 1, 1);
    val1 = VCell.OlePropertyGet("Value");
    VCell = xlSheet.OlePropertyGet("Cells", 1, 2);
    val2 = VCell.OlePropertyGet("Value");
    VCell = xlSheet.OlePropertyGet("Cells", 1, 3);
    val3 = VCell.OlePropertyGet("Value");
    int i = 4;
    while((val1.Length() != 0) && (val2.Length() != 0) && (val3.Length() != 0))
    {

    //셀좌표(Y, X)인 셀을 얻는다.
        VCell = xlSheet.OlePropertyGet("Cells", i, 1);
        val1 = VCell.OlePropertyGet("Value");
        VCell = xlSheet.OlePropertyGet("Cells", i, 2);
        val2 = VCell.OlePropertyGet("Value");
        VCell = xlSheet.OlePropertyGet("Cells", i, 3);
        val3 = VCell.OlePropertyGet("Value");
       
        if( Query1->Active ) Query1->Active = false;
        Query1->SQL->Clear();
          SQLCommand1 = "INSERT INTO excel ";
        SQLCommand1 = SQLCommand1 + "VALUES ('" + val1 + "','";
        SQLCommand1 = SQLCommand1 + val2 + "','";
        SQLCommand1 = SQLCommand1 + val3 + "') ";
         Query1->SQL->Add( SQLCommand1 );
          Query1->ExecSQL();
        i++;
    }

    xlBooks.OleProcedure("Close");
    xlApp.OleProcedure("Quit");



webb 님이 쓰신 글 :
: Q&A를 뒤져서 엑셀파일의 셀값을 읽어들이는것은 알아냈습니다.
:
: ==>
:
: void __fastcall TForm1::Button1Click(TObject *Sender)
: {
:   Variant xlApp;
:
:   //Variant로 엑셀 인스턴스를 만든다.
:   xlApp = Variant::CreateObject("Excel.Application");
:
:   // 엑셀의 워크북 오브젝트 접근
:   Variant xlBooks;
:   xlBooks = xlApp.OlePropertyGet("Workbooks");
:   // 존재하는 엑셀 파일을 연다.
:   xlBooks.OleProcedure("Open", "c:\\Book1.xls");
:
:   // 어플리케이션 내에서 첫번째 워크북을 얻는다.
:   Variant xlBook = xlBooks.OlePropertyGet("Item", 1);
:   // 워크시트들을 관리할 수 있는 오브젝트를 얻는다.
:   Variant xlSheets = xlBook.OlePropertyGet("Worksheets");
:   // 첫번째 워크시트를 얻는다.
:   Variant xlSheet = xlSheets.OlePropertyGet("Item", 1);
:
:   // 셀로 작업할 경우
:   Variant VCell;
:   //셀좌표(Y, X)인 셀을 얻는다.
:   VCell = xlSheet.OlePropertyGet("Cells", 1, 1);
:   Caption = VCell.OlePropertyGet("Value"); //셀값을 읽어온다.
:
:   // 빠져나갈 때
:   xlBooks.OleProcedure("Close");
:   xlApp.OleProcedure("Quit");
: }
:
: 제가 하고싶은것은 엑셀시트의 전체 레코드를 다른 table로 append하고 싶습니다.
:
: 주된 로직은 엑셀시트의 내용(RECORD)을 SQL DB TABLE에 APPEND하는 것입니다.
:
: 사용자가 엑셀을 실행하고 범위를 택해 복사(CNTR+C)하여 DBGRID에 붙여놓거나 아님 엑셀파일을 지정하여
: RECORD를 읽어 APPEND했으면 좋겠습니다.
:
: 위 예제를 보면 FOR 문으로 어떻게 할 수 있을거 같은데 일반 TABLE이면 BOF로 끝을 지정할 수 있는데
: 여기서는 무얼 써야하는지 모르겠군요.
:
: 확답이 아니더라고 도움이 될만한 조언 부탁드립니다.
:
:

+ -

관련 글 리스트
13316 [질문]Excel파일 레코드 읽기 webb 1267 2001/12/03
13494     Re:[질문]Excel파일 레코드 읽기 건전맨 1613 2001/12/09
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.