Options

Upload a .txt file through the RTC into Excel Buffer Table

TESDarrenATESDarrenA Member Posts: 11
edited 2010-05-28 in NAV Three Tier
Hi,

I am having a few issues, when using the RTC, I am running a codeunit which reads in a .txt by char and inserts it into the Excel buffer table. If I run the codeunit through Classic it works perferct but through the RTC I get the error:

Invalid data encountered in Stream, unable to read text.

Code:

ImportCSVtoExcelBuffer(VAR VfilFile : File;VAR RrecExcelBufferTemp : TEMPORARY Record "Excel Buffer";VchrSeperator : Char;VchrQualifier

RrecExcelBufferTemp.RESET;
RrecExcelBufferTemp.DELETEALL;
 
LintRowCount :=1;
LintColumnCount :=1;
 
VfilFile.TEXTMODE(FALSE);
VfilFile.SEEK(0);
 
WHILE LintFileCount <= VfilFile.LEN DO BEGIN
  LintFileCount+=1;
  
  VfilFile.READ(LchrReadInChar);

  CASE LchrReadInChar OF
    VchrSeperator:
      BEGIN
        RrecExcelBufferTemp.INIT;
        RrecExcelBufferTemp."Row No." := LintRowCount;
        RrecExcelBufferTemp."Column No." := LintColumnCount;
        RrecExcelBufferTemp."Cell Value as Text" := LtxtReadInText;
        RrecExcelBufferTemp.INSERT;
        LintColumnCount +=1;
        LtxtReadInText :='';
      END;
    VchrQualifier:
      BEGIN
      END;
    VchrLineBreak:
      BEGIN
        RrecExcelBufferTemp.INIT;
        RrecExcelBufferTemp."Row No." := LintRowCount;
        RrecExcelBufferTemp."Column No." := LintColumnCount;
        RrecExcelBufferTemp."Cell Value as Text" := LtxtReadInText;
        RrecExcelBufferTemp.INSERT;
        LintRowCount +=1;
        LintColumnCount :=1;
        LtxtReadInText :='';

      END;
    ELSE BEGIN
      IF (LchrReadInChar >=32) AND (LchrReadInChar <=126) THEN
      LtxtReadInText := LtxtReadInText + FORMAT(LchrReadInChar);
    END;
  END;
END;
CreateHeader(RrecExcelBufferTemp);
EXIT(LintRowCount-1);

Is there an easier way of possibly doing this, I tried this way as the .txt file contains lots of ,'s and "? ](*,) ](*,) ](*,)

Please note that it doesn't get into my CreateHeader function but it does read in every chr from the file (I inserted every Chr into a table to test) but then I get the above error. :( Do I have to tell it to stop reading in or commit it somewhere?

Thanks for your time.

Darren A

Comments

  • Options
    TESDarrenATESDarrenA Member Posts: 11
    Or has anyone imported a text file through the RTC to create records for example in tb 36 & tb 37

    This is getting really urgent now.

    Hope someone can help :-k
Sign In or Register to comment.