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
[13493] Excel 파일 불러오기?? 한꼬맹이님 답변주세요...
건전맨 [hoonlim] 2327 읽음    2001-12-09 16:52
엑셀 파일을 불러와서 테이블에 집어넣고 그리고 테이블에 있는 내용을 가져옵니다.
OpenDialog는 잘 되는데 제가 원하는 파일이 아닙니다.

======>

void __fastcall TMainForm::BtnOpenClick(TObject *Sender)
{
    OpenDialog1->Title    = "Excel 파일 읽어오기";
    if (OpenDialog1->Execute())
    {
        OpenData(OpenDialog1->FileName);
    }
}
//---------------------------------------------------------------------------
void TMainForm::OpenData(AnsiString strPath)
{
    Table1->Close();

    AnsiString SQLCommand1;

    if( Query1->Active ) Query1->Active = false;
    Query1->SQL->Clear();
      SQLCommand1 = "DELETE FROM excel";
      Query1->SQL->Add( SQLCommand1 );
      Query1->ExecSQL();

    Variant xlApp;
    Variant ttt = OpenDialog1->FileName;
    //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, VCell1;
    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");
        val3 = val3.SubString(1,3) + "-" + val3.SubString(4,3) + "-" + val3.SubString(7,2) + "-"  + val3.SubString(9,4);
        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");

    Table1->Open();
}

제 생각에는 xlBooks.OleProcedure("Open", "c:\\Book1.xls");
여기가 문제인 것 같은데요..
c:\\Book1.xls 파일은 잘 열립니다.
그런데 다른 경로에 있는 파일을 가져와도 c:\\Book1.xls 파일이 열립니다.
제가 원하는 경로에 있는 파일을 가져올려면 어떻게 해야 하나요?
한꼬맹이님 답변 부탁드립니다.
아시는 분 있으시면 답변 부탁드리고요...

+ -

관련 글 리스트
13493 Excel 파일 불러오기?? 한꼬맹이님 답변주세요... 건전맨 2327 2001/12/09
13504     Re:Excel 파일 불러오기?? 한꼬맹이님 답변주세요... 권대길.한꼬맹이 1657 2001/12/10
13522         Re:Re:[다른질문]데이터양이 많을때??...한꼬맹이님 답변주세요... 건전맨 1197 2001/12/10
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.