Table of Contents

Text File Importer

Functions to import from text files of various formats.

Object Definition

Object TypeCodeunit
Object ID70327087
Object NameQWETB Text File Importer

Procedures

Name Description
GetFieldValue(Integer; Integer): Text Gets the value of a specific column in a specific line.
GetNumberOfLines(): Integer Gets the total number of imported lines.
GetTextBuffer(Record "QWETB Text Buffer" temporary) Gets the Text Buffer that has been filled with the imported data.
GetTextLine(List of [Text]): Boolean Gets the columns of the next line of the import.
GetTextLine(array[500] of Text; Integer): Boolean Gets the columns of the next line of the import.
LoadData(Code[20]; Codeunit "QWETB Temp Blob"): Integer Imports data from a Temp Blob codeunit.
LoadData(Code[20]; Codeunit "Temp Blob"): Integer Imports data from a Temp Blob codeunit.
LoadData(Record "QWETB File Settings" temporary; Codeunit "QWETB Temp Blob"): Integer Imports data from a Temp Blob codeunit.
LoadData(Record "QWETB File Settings" temporary; Codeunit "Temp Blob"): Integer Imports data from a Temp Blob codeunit.
LoadData(Record "QWETB File Settings" temporary; Record "QWETB Fixed Width Column" temporary; Codeunit "QWETB Temp Blob"): Integer Imports data from a Temp Blob codeunit.
LoadData(Record "QWETB File Settings" temporary; Record "QWETB Fixed Width Column" temporary; Codeunit "Temp Blob"): Integer Imports data from a Temp Blob codeunit.
Txt2Date(Record "QWETB File Settings" temporary; Text): Date Converts text to date, according to provided settings.
Txt2Date(Text): Date Converts text to date, according to configured settings.
Txt2Dec(Record "QWETB File Settings" temporary; Text): Decimal Converts text to decimal, according to configured settings.
Txt2Dec(Text): Decimal Converts text to decimal, according to configured settings.

Deprecated Procedures

Name Description
CleanTxt(Text): Text Removes all characters with character code less than 32.
GetColumnValue(Record "QWETB Text Buffer" temporary; Integer; Integer) Gets a specific column in a specific line.
GetNoOfRec(): Integer Gets the total number of imported lines.
IsFixLength(Code[20]): Boolean Gets if an Import Type is of Fixed Length type.
LoadData(Code[20]; Record "QWETB tTempBlob" temporary): Integer Imports data from a TempBlob record.
LoadData(Record "QWETB File Settings" temporary; Record "QWETB Fixed Width Column" temporary; Record "QWETB tTempBlob" temporary): Integer Imports data from a TempBlob record.
LoadData(Record "QWETB File Settings" temporary; Record "QWETB tTempBlob" temporary): Integer Imports data from a TempBlob record.
ReadTextBLOB(Codeunit "Temp Blob"): Integer Imports from a Temp Blob codeunit.
ReadTextBLOB(Record "QWETB tTempBlob" temporary): Integer Imports from a TempBlob record.
SetFixedLengthColumn(Record "QWETB Fixed Length Column No" temporary; Integer; Integer; Integer) Adds a column definition to the Fixed Length settings.
SetFixedLengthImportType(Record "QWETB Import Type" temporary; Record "QWETB Fixed Length Column No" temporary) Sets the settings that will be used for import a fixed length file.
SetFixedLengthToColumnNo(Record "QWETB Fixed Length Column No" temporary) Sets the Fixed Length Settings that should be used for this import.
SetImportType(Record "QWETB Import Type" temporary) Sets the settings that will be used for import.
Truncate(Text; Text) Copies a text to another text, truncates the text at the max length of the target text if needed.

Example

Import from an UTF8 encoded file with Tab as a field separator.

TempFileSettings.Init();
TempFileSettings.Encoding := TempFileSettings.Encoding::UTF8;
TempFileSettings."Data Type" := TempFileSettings."Data Type"::Delimited;
TempFileSettings.Delimiter := TempFileSettings.Delimiter::Tab;
TextFileImporter.LoadData(TempFileSettings, TempBlob);
while TextFileImporter.GetTextLine(FieldList) do begin
    LineNo += 1;
    for FieldNo := 1 to FieldList.Count() do begin
        if not Confirm('Line %1, Column %2: %3', true, LineNo, FieldNo, FieldList.Get(FieldNo)) then
            error('');
    end;
end;

Import data from an UTF8 encoded file with Tab as a field separator to a table named Import Buffer. Skip first line if File Settings is configured with "Column Headers" = true

    local procedure ImportTextFileToImportBuffer(TempBlob: Codeunit "Temp Blob"): Boolean
   var
       ImportBuffer: Record "Customer Update Buffer";
       TempFileSettings: Record "QWETB File Settings" temporary;
       TextFileImporter: Codeunit "QWETB Text File Importer";
       LineNo: Integer;
       n: Integer;
       ImportMsg: Label '%1 lines have been imported.', Comment = '%1 = Number of Lines';
   begin
       TempFileSettings.Init();
       TempFileSettings.Encoding := TempFileSettings.Encoding::UTF8;
       TempFileSettings."Data Type" := TempFileSettings."Data Type"::Delimited;
       TempFileSettings.Delimiter := TempFileSettings.Delimiter::Tab;
       TempFileSettings."Column Headers" := true;

       TextFileImporter.LoadData(TempFileSettings, TempBlob);

       for LineNo := 1 to TextFileImporter.GetNumberOfLines() do begin
           if (LineNo = 1) and TempFileSettings."Column Headers" then begin
               ; // Skip first line if it contains column headers
           end else begin
               ImportBuffer.Init();
               ImportBuffer.Field1 := TextFileImporter.GetFieldValue(LineNo, 1);
               ImportBuffer.Field2 := TextFileImporter.GetFieldValue(LineNo, 2);
               ImportBuffer.Field3 := TextFileImporter.GetFieldValue(LineNo, 3);
               ImportBuffer.Field4 := TextFileImporter.GetFieldValue(LineNo, 4);
               ImportBuffer.Insert(true);
               n += 1;
           end;
       end;
       Message(ImportMsg, n);
   end;

This documentation is generated from Smart Toolbox v27.1