|
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
OpenDialog1->Execute();
fnOpenExcel(OpenDialog1->FileName);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::fnOpenExcel(AnsiString szOpenFileName)
{
Variant xlApp, xlBooks;
xlApp = Variant::CreateObject("Excel.Application");
xlBooks = xlApp.OlePropertyGet("Workbooks");
//WideString aString = "c:\\test.xls";
xlBooks.OleProcedure("Open", szOpenFileName.c_str());
Variant xlBook = xlBooks.OlePropertyGet("Item", 1);
Variant xlSheets = xlBook.OlePropertyGet("Worksheets");
Variant xlSheet = xlSheets.OlePropertyGet("Item", 1); // 1번 Sheet 가져오기
Variant VCell;
AnsiString val1,val3;
int row_cnt = xlSheet.OlePropertyGet("UsedRange").OlePropertyGet("Rows").OlePropertyGet("Count"); //row갯수
int col_cnt = xlSheet.OlePropertyGet("UsedRange").OlePropertyGet("Columns").OlePropertyGet("Count"); //col갯수
sgGrid->ColCount = col_cnt;
sgGrid->RowCount = row_cnt;
try
{
for(int row = 0; row < row_cnt; row++)
{
for(int col = 0;col < col_cnt; col++)
{
VCell = xlSheet.OlePropertyGet("Cells", row + 1, col + 1);
val1 = VCell.OlePropertyGet("Value");
sgGrid->Cells[col][row] = val1;
}
}
xlBooks.OleProcedure("Close");
xlApp.OleProcedure("Quit");
}
catch(...)
{
xlBooks.OleProcedure("Close");
xlApp.OleProcedure("Quit");
}
}
엑셀파일에 있는 내용이 행이 2500줄 정도 되는데
가지고 오는데 1시간 넘게 걸려요 ㅠ,.ㅠ
좀 알려주세요
|