|
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로 끝을 지정할 수 있는데
: 여기서는 무얼 써야하는지 모르겠군요.
:
: 확답이 아니더라고 도움이 될만한 조언 부탁드립니다.
:
:
|