Q&A

  • 엑셀변환 중 Error
새로 프로젝트를 만들어 변환하면 변환이 되는데

기존프로그램에서 엑셀변환하면
'OLE erroe 800A03EC'
에러 메시지가 나나납니다.


with ASG do                                                                                                                    
  begin
    XTitle := VarArrayCreate([1, ColCount], VarVariant);                        // 타이틀 처리변수                              
    XArr := VarArrayCreate([1, ColCount], VarVariant);                          // 데이타 처리변수
    try                                                                                                                          
      XL := CreateOLEObject('Excel.Application');                               // 엑셀을 실행                                  
    except                                                                                                                      
      MessageDlg('Excel이 설치되어 있지 않습니다.', MtWarning, [mbok], 0);                                                      
      Exit;                                                                                                                      
    end;                                                                                                                        

    XL.WorkBooks.Add;                                                           // 새로운 페이지 생성
    XL.Visible := True;
                                                                                                                                
    k := 1;
    for i := 0 to ColCount-1 do                                                                                                  
    begin                                                                                                                        
      XTitle[i+1] := Cells[i, 0].AsString;                                                                                                
    end;

    XL.Range['A1', CHR(64 + ColCount) + '1'].Value := XTitle; //여기서 Error 가 나타납니다.                
    for i := 1 to rowcount-1 do
    begin
      for j := 0 to ColCount-1 do
      begin
//        XArr[j+1] := '''' + Cells[j,i]                                          // string데이타값넣기
        XArr[j+1] := Cells[j,i].AsString                                          // string데이타값넣기
      end;
      XL.Range['A' + IntToStr(k+1), CHR(64 + ColCount) + IntToStr(k+1)].Value := XArr;                       // 셀에 값을 넣는다.
      Inc(k);
    end;
    XL.Range['A1', CHR(64 + ColCount) + IntToStr(k)].Select;                  // 셀 크기 조정
    XL.Selection.Columns.AutoFit;
    XL.Range['A1', 'A1'].Select;                                                                                                
  end;              

//따라가보면 ComObj 에서 여기서 에러가 발생됩니다.
procedure DispCallError(Status: Integer; var ExcepInfo: TExcepInfo;
  ErrorAddr: Pointer; FinalizeExcepInfo: Boolean);
var
  E: Exception;
begin
  if Status = Integer(DISP_E_EXCEPTION) then
  begin
    with ExcepInfo do
      E := EOleException.Create(bstrDescription, scode, bstrSource,
        bstrHelpFile, dwHelpContext);
    if FinalizeExcepInfo then
      Finalize(ExcepInfo);
  end else
    E := EOleSysError.Create('', Status, 0);
  if ErrorAddr <> nil then
    raise E at ErrorAddr
  else
    raise E;
end;

고수님들의 한수를 부탁드립니다.
0  COMMENTS