티스토리 뷰
void __fastcall GetExcel(void)
{
Variant XlApp;
Variant XlBooks;
Variant XlBook;
Variant XlSheets;
Variant XlSheet;
Variant VCell;
AnsiString CelValue;
int ColCount;
int RowCount;
int Row, Col;
AnsiString Data[3];
char StopFlag = FALSE;
try {
XlApp = Variant::CreateObject("Excel.Application");
XlBooks = XlApp.OlePropertyGet("Workbooks");
XlBooks.OleProcedure("Open", WideString(m_ExcelFile));
XlBook = XlBooks .OlePropertyGet("Item", 1);
XlSheets = XlBook .OlePropertyGet("Worksheets");
XlSheet = XlSheets .OlePropertyGet("Item", 1);
ColCount = XlSheet .OlePropertyGet("UsedRange").OlePropertyGet("Columns" ).OlePropertyGet("Count");
RowCount = XlSheet .OlePropertyGet("UsedRange").OlePropertyGet("Rows" ).OlePropertyGet("Count");
ProgressBar->MaxValue = RowCount;
for(Row = 2; Row <= RowCount; Row ++) {
memset(&Data, 0, sizeof(Data));
for(Col = 1; Col <= ColCount; Col ++) {
VCell = XlSheet .OlePropertyGet("Cells", Row, Col);
CelValue = VCell .OlePropertyGet("Value");
Data[Col - 1] = CelValue;
}
// 데이터 처리
if(!DataToDB(Data, Row)) StopFlag = TRUE;
if(StopFlag) break;
}
} catch(Exception &e) {
MessageBox(Handle, "현재 엑셀이 설치 되어 있지 않거나 작업 중 오류가 발생하였습니다.\
\n\n엑셀을 설치하시거나 재 설치 하여 주십시요.", MSG_TITLE, MB_ICONWARNING);
}
XlBook .OleProcedure("Close");
XlApp .OleProcedure("Quit");
XlApp = Unassigned;
XlBooks = Unassigned;
XlBook = Unassigned;
XlSheets = Unassigned;
XlSheet = Unassigned;
if(StopFlag) MessageBox(Handle, "작업이 취소 되었습니다.", MSG_TITLE, MB_ICONWARNING);
else MessageBox(Handle, "작업이 완료 되었습니다.", MSG_TITLE, MB_ICONINFORMATION);
}
'프로그래밍 > C++ Builder' 카테고리의 다른 글
로컬 IP 알아내기 (0) | 2019.07.16 |
---|---|
버튼으로 팝업 메뉴 띄을때 좌표 표시 (0) | 2019.07.16 |
윈도우 부팅시 자동 실행 (0) | 2019.07.16 |
초간단 암호화 (0) | 2019.07.16 |
레지스트리 쓰고, 읽기 (0) | 2019.07.16 |
- Total
- Today
- Yesterday