Table of Contents

File Importer

Functions to import data from files of various formats, using File Settings.

Object Definition

Object TypeCodeunit
Object ID70327103
Object NameQWETB File Importer

Procedures

Name Description
GetColumnValue(Integer; Integer): Text Gets the Column Value at a given position in the imported file
GetColumnValue(Integer; Integer; Text): Boolean Gets the Column Value at a given position in the imported file
GetNextLine(List of [Text]): Boolean Gets the columns of the next line of the imported file.
GetNumberOfLines(): Integer Gets the total number of lines in the imported file.
Init(Code[20]) Initializes the File Importer codeunit.
LoadData(Codeunit "QWETB Temp Blob"): Integer Imports data from a Temp Blob codeunit.
LoadData(Codeunit "Temp Blob"): Integer Imports data from a Temp Blob codeunit.
Txt2Date(Text): Date Converts text to date, according to File Setting set by the Init() procedure.
Txt2Dec(Text): Decimal Converts text to decimal, according to File Setting set by the Init() procedure.

Deprecated Procedures

Name Description
GetTextBuffer(Record "QWETB Text Buffer" temporary) Gets the Text Buffer that has been filled with the imported data.
LoadData(Record "QWETB tTempBlob" temporary): Integer Imports data from a TempBlob record.

Example

Import an Excel file to a table named Import Buffer. Skip first line if File Settings is configured with "Column Headers" = true

    local procedure ImportToImportBuffer(TempBlob: Codeunit "Temp Blob"): Boolean
    var
        ImportBuffer: Record "Customer Update Buffer";
        FileSettings: Record "QWETB File Settings";
        FileImporter: Codeunit "QWETB File Importer";
        LineNo: Integer;
        n: Integer;
        ImportMsg: Label '%1 lines have been imported.', Comment = '%1 = Number of Lines';
    begin
        if not FileSettings.Get('ImportSample') then begin
            FileSettings.Init();
            FileSettings.Code := 'ImportSample';
            FileSettings."Data Type" := FileSettings."Data Type"::Excel;
            FileSettings."Column Headers" := true;
            FileSettings.Insert(true);
        end;

        FileImporter.Init(FileSettings.Code);
        FileImporter.LoadData(TempBlob);

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

This documentation is generated from Smart Toolbox v27.1