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
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.

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 v28.0