Q&A

  • 델파이에서 엑셀을 읽어올때 "읽기전용'으로 읽으려면 어떻게 해야 하나요?
엑셀을 읽어서 데이터를 뽑긴 했는데....
에러가 생깁니다.....

온도측정기(하드웨어)가 엑셀에 데이터를 뿌려주면(갱신주기가 1분입니다) 그 엑셀파일을 읽어서 서버에 데이터를 저장하는데요...
문제는 온도측정기에서 엑셀로 뿌려주는 프로그램(A)을 제가 짠게 아니구..소스도 없어서...
현재 방법으론 엑셀을 읽어서 제가 만든프로그램(B)으로 서버에 저장할라구 하는데요....

문제는
1.A에서 데이터를 엑셀에 쓰고있을때 B에서 읽으려고 하거나
2.B에서 먼저 파일을 읽고 있는데 A에서 데이터를 쓰려고 할때

원인은
1,2번의경우 A(B)에서 이미 읽고 쓰기로 파일을 열었는데 B(A)에서도 읽고쓰기 속성으로 열려고 해서 발생하는거 같습니다.

해결책으로 생각한것이 B프로그램에서 무조건 읽기 전용으로 읽고 A프로그램에선 읽고쓰기속성으로 열면 될거 같긴 한데요....
가능할런지요...
그리고 읽기전용으로 읽으려면 어떻게 해야 하는지요....

파일을 열때 다음과 같은 방법으로 했습니다.
변수 Ex: varaint; 이런식으로 선언하고
    Ex := CreateOLEObject('Excel.Application');
    Ex.WorkBooks.Open(edt_FileName.Text);
이렇게 엑셀을 열고 각 셀에서 파일을 읽어 왔습니다.

도움부탁드립니다....
좀 급하네요. ㅠㅠ
3  COMMENTS
  • Profile
    성더기 2004.01.29 23:11
    다른 방법이 있는지는 모르겠습니다만..
    복사를 하는 방법은 어떤지요
    원래 파일은 그냥 그대로 두고 그 파일을 새로운 파일로 한개 복사하여
    복사된 파일의 데이터를 읽어 오는 방법은 쓰는건...
    안될려나요?ㅡㅡ;;
  • Profile
    Crazy 2004.01.29 23:54
    Ex.WorkBooks.Open(edt_FileName.Text); ==> 요거를
    Ex.WorkBooks.Open(edt_FileName.Text, fmOpenRead);
    이렇게 한번 해보세요.

    {$IFDEF MSWINDOWS}
      fmOpenRead       = $0000;
      fmOpenWrite      = $0001;
      fmOpenReadWrite  = $0002;

      fmShareCompat    = $0000 platform;
      fmShareExclusive = $0010;
      fmShareDenyWrite = $0020;
      fmShareDenyRead  = $0030 platform;
      fmShareDenyNone  = $0040;

    {$ENDIF}

    Description

    The file open mode constants are used when a file or stream is opened to control how it can be shared.

    The TFileStream constructor has a Mode parameter that you can set to one of these constants:

    Constant        Definition

    fmCreate        If the file exists, open for write access, otherwise, create a new file. Unlike the other constants, which are declared in the SysUtils unit, this constant is declared in classes.pas.
    fmOpenRead        Open for read access only.
    fmOpenWrite        Open for write access only.
    fmOpenReadWrite        Open for read and write access.
    fmShareCompat        Compatible with the way FCBs are opened. Do not use this mode in cross-platform applications.
    fmShareExclusive        Read and write access is denied.

    fmShareDenyWrite        Write access is denied.
    fmShareDenyRead        Read access is denied. Do not use this mode in cross-platform applications.
    fmShareDenyNone        Allows full access for others.


  • Profile