uses Windows, SysUtils, Forms, Variants, ComObj, OleServer;

...

...

...


function GetExcelText(fName: String): String;

var

  Excel: OleVariant;

  i, j: Integer;

  tmpString: String;


begin

  Result:='';


  // 엑셀 어플리케이션 생성

  try

    Excel:=CreateOleObject('Excel.application');

  except

    MessageBox(0,'Excel이 설치되어 있지 않습니다.','',MB_OK);

    Exit;

  end;


  // 파일이 있는지 확인

  if not FileExists(fName) then begin

    MessageBox(0,'파일이 없습니다','',MB_OK);

    Exit;

  end;


  // WorkBooks Open

  Excel.Workbooks.Open(fName);


  // Cell 의 내용을 받아옴

  for i:=1 to Excel.ActiveSheet.UsedRange.Rows.Count do begin

    for j:=1 to Excel.ActiveSheet.UsedRange.Columns.Count do begin

      tmpString:=Excel.Cells[i, j];

      if Length(Trim(tmpString))>0 then Result:=Result+#13#10+tmpString;


      Application.ProcessMessages;

    end;

  end;


  // 해제과정

  Excel.Workbooks.Close;

  Excel.Quit;

  Excel:=Unassigned;

end;

+ Recent posts