Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 Q&A
Delphi Programming Q&A
[11842] [질문] 엑셀파일로 저장 시 에러 발생.
이창엽 [nakednaura] 2746 읽음    2008-03-19 13:54
Data를 엑셀 파일로 저장하려고 합니다.
아래와 같은 코드로 작성하여 엑셀파일을 저장을 실행하면 정상적인 데이터를 가진 엑셀파일이 생성됩니다.
그러나 문제는 엑셀파일이 저장되고 난 후 다음과 같은 오류 메시지가 뜬 다는 겁니다. 오류 보고서에 있는 데이터 종류 보기를 클릭하면 아래의 오류 서명 정보가 나옵니다.
꼭 좀 도와주세요. 도대체 왜 문제가 있는 지 모르겠습니다.
윈도우즈 2000, MS Office 버전 2003 사용

오류메시지----------------------------------------------------------------------------------
Microsoft Office Excel에 문제가 발생했기 때문에 프로그램을 종료해야 합니다. 불편을 끼쳐드려 죄송합니다.
-----------------------------------------------------------------------------------
오류 서명--------------------------------------------------------
AppName: excel.exe    AppVer: 11.0.8206.0     AppStamp: 479fc4d6
ModName: unknown      ModVer: 0.0.0.0      ModStamp:00000000
fDebug: 0             Offset: 01accee2
------------------------------------------------------------------
소스 코드-----------------------------------------------------------------------------
procedure TForm1.SaveAsExcel(aMediatype : string);
var
   xlWk, xlSheet, xlAppl : Olevariant;
   filepath : string;
   i, j, ip_index : integer;
begin
   xlAppl := CreateOleObject('Excel.Application');
   //엑셀 파일 설정
   filepath := copy(ParamStr(0), 1, lastdelimiter('\',ParamStr(0)))+ aMediatype + '.xls';
   if FileExists(filepath) then
    DeleteFile(filepath);
   xlWK := xlAppl.WorkBooks.add;
   //종합 결과(정상+오류) Sheet 생성---------------------------------------------------------------
   xlSheet := xlWK.WorkSheets.add;
   xlSheet.name := '종합 결과';
   //엑셀 시트 환경 설정-----------------
   xlSheet.Cells[1, 1].Value := 'IP';
   xlSheet.Cells[1, 2].Value := '반영 날짜';
   xlSheet.Cells[1, 3].Value := '파일명';
   xlSheet.Cells[1, 4].Value := '상태';
   xlSheet.Cells[1, 1].Font.Size := 12;
   xlSheet.Cells[1, 1].Font.Bold := true;
   xlSheet.Cells[1, 2].Font.Size := 12;
   xlSheet.Cells[1, 2].Font.Bold := true;
   xlSheet.Cells[1, 3].Font.Size := 12;
   xlSheet.Cells[1, 3].Font.Bold := true;
   xlSheet.Cells[1, 4].Font.Size := 12;
   xlSheet.Cells[1, 4].Font.Bold := true;
   //---------------------------------------
   //데이타 출력
   if ResultList.Count > 0 then
   begin
     j := 2;
     try
       for i := 0 to ResultList.Count -1 do
         if CompareText(ResultRec(ResultList.Items[i]^).Media_type, aMediatype) = 0 then
            begin
            ip_index := StrToint(ResultRec(ResultList.Items[i]^).IP_addr);
            xlSheet.Cells[j, 1].Value := ServerRec(ServerList.Items[ip_index]^).Ip_addr; //인덱스에서 실제 ip로 변환
            xlSheet.Cells[j, 2].Value := ResultRec(ResultList.Items[i]^).fDate;
            xlSheet.Cells[j, 3].Value := ResultRec(ResultList.Items[i]^).File_name;
            xlSheet.Cells[j, 4].Value := ResultRec(ResultList.Items[i]^).Status;
            inc(j);
            end;
       xlAppl.Visible := True;
     except   end;
   end;
  //---------------------------------------------------------------------------------------------------
  //오류 결과 Sheet 생성---------------------------------------------------------------
  xlSheet := xlWK.WorkSheets.add;
  xlSheet.name := '오류 결과';
  //엑셀 시트 환경 설정-----------------
  xlSheet.Cells[1, 1].Value := 'IP';
  xlSheet.Cells[1, 2].Value := '반영 날짜';
  xlSheet.Cells[1, 3].Value := '파일명';
  xlSheet.Cells[1, 4].Value := '상태';
  xlSheet.Cells[1, 1].Font.Size := 12;
  xlSheet.Cells[1, 1].Font.Bold := true;
  xlSheet.Cells[1, 2].Font.Size := 12;
  xlSheet.Cells[1, 2].Font.Bold := true;
  xlSheet.Cells[1, 3].Font.Size := 12;
  xlSheet.Cells[1, 3].Font.Bold := true;
  xlSheet.Cells[1, 4].Font.Size := 12;
  xlSheet.Cells[1, 4].Font.Bold := true;
  //---------------------------------------
  //데이타 출력
  if NonOk_ResultList.Count > 0 then
  begin
    j := 2;
    try
      for i := 0 to NonOk_ResultList.Count -1 do
        if CompareText(ResultRec(NonOk_ResultList.Items[i]^).Media_type, aMediatype) = 0 then
        begin
          ip_index := StrToint(ResultRec(NonOk_ResultList.Items[i]^).IP_addr);
          xlSheet.Cells[j, 1].Value := ServerRec(ServerList.Items[ip_index]^).Ip_addr; //인덱스에서 실제 ip로 변환
          xlSheet.Cells[j, 2].Value := ResultRec(NonOk_ResultList.Items[i]^).fDate;
          xlSheet.Cells[j, 3].Value := ResultRec(NonOk_ResultList.Items[i]^).File_name;
          xlSheet.Cells[j, 4].Value := ResultRec(NonOk_ResultList.Items[i]^).Status;
          inc(j);
        end;
      xlAppl.Visible := True;
     except   end;
  end;
  //---------------------------------------------------------------------------------------------------
  try
  //엑셀 파일 저장
    xlWK.SaveAs(filepath);
    XlAppl.DisplayAlerts := False; // Quit 할때 저장여부 묻는 Dialog 안띄우게 함
  finally
  // 엑셀 닫기
    xlWK.Close;
    xlWK := unassigned;
    xlSheet:= unassigned;
    xlAppl.Quit;
    xlAppl := unassigned;
end;
end;

+ -

관련 글 리스트
11842 [질문] 엑셀파일로 저장 시 에러 발생. 이창엽 2746 2008/03/19
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.