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
[16741] C++Builder를 이용하여 기존 Excel화일을 편집시 기존화일이 열리지 않아요 도와주셔요
김결철 [] 2355 읽음    2002-03-25 13:15
존재하는 화일을 열려고 하면  xlBooks.OleProcedure("Open", "testAC.xls"); 에서 예외 오류가
발생합니다. 가르쳐 주셔요.....



void __fastcall TForm1::Button1Click(TObject *Sender)
{
Variant xlApp;
if (xlApp.IsEmpty())
{//Variant로 엑셀 인스턴스를 만든다.
  xlApp = Variant::CreateObject("Excel.Application");
  ShowMessage("New Object");
}
// 엑셀이 보이게끔 한다.
xlApp.OlePropertySet("Visible", true);
// 엑셀의 워크북 오브젝트 접근
Variant xlBooks;
xlBooks = xlApp.OlePropertyGet("Workbooks");
// 존재하는 엑셀 파일을 연다.
xlBooks.OleProcedure("Open", "testAC.xls");
// 만약에 만들 경우는 xlBooks.OleProcedure("Add");

// 어플리케이션 내에서 첫번째 워크북을 얻는다.
Variant xlBook = xlBooks.OlePropertyGet("Item", 1);
// 워크시트들을 관리할 수 있는 오브젝트를 얻는다.
Variant xlSheets = xlBook.OlePropertyGet("Worksheets");
// 첫번째 워크시트를 얻는다.
Variant xlSheet = xlSheets.OlePropertyGet("Item", 1);

// 셀로 작업할 경우
Variant VRange;
VRange = xlSheet.OlePropertyGet("Range", "A10");
VRange.OlePropertySet("Value", "CellA10");
VRange = xlSheet.OlePropertyGet("Range", "A11");
VRange.OlePropertySet("Value", "CellA11");
VRange = xlSheet.OlePropertyGet("Range", "A12");
VRange.OlePropertySet("Value", "CellA12");
VRange = xlSheet.OlePropertyGet("Range", "B10");
VRange.OlePropertySet("Value", "CellB10");
VRange = xlSheet.OlePropertyGet("Range", "B11");
VRange.OlePropertySet("Value", "CellB11");
VRange = xlSheet.OlePropertyGet("Range", "B12");
VRange.OlePropertySet("Value", "CellB12");

// 2*2 셀을 지운다.
VRange = xlSheet.OlePropertyGet("Range", "A10:B10");
VRange.OleFunction("ClearContents");

// 값을 계산할 때
xlSheet = xlApp.OlePropertyGet("ActiveSheet");
for (int i = 1; i <= 8; i++)
     xlSheet.OlePropertySet("cells", 1, i, i);
xlSheet.OlePropertyGet("Range", "A2:H9").OlePropertySet("FormulaR1C1", "=R[-1]C*2");
// 빠져나갈 때
xlBooks.OleProcedure("Close");
if (::MessageBox(0, " 엑셀을 빠져나가시겠습니까?", "Test",
  MB_YESNO | MB_ICONASTERISK) == IDYES)
  xlApp.OleProcedure("Quit");
}

+ -

관련 글 리스트
16741 C++Builder를 이용하여 기존 Excel화일을 편집시 기존화일이 열리지 않아요 도와주셔요 김결철 2355 2002/03/25
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.