OBJECT Report 50000 Import from Excel Template { OBJECT-PROPERTIES { Date=18/10/14; Time=09:49:15; Modified=Yes; Version List=NAVW17.10; } PROPERTIES { CaptionML=[ENU=Import from Excel Template; ENG=Import from Excel Template]; ProcessingOnly=Yes; OnPreReport=VAR BusUnit@1000 : Record 220; BEGIN TempExcelBuf.LOCKTABLE; TempExcelBuf.OpenBook(ServerFileName,SheetName); TempExcelBuf.ReadSheet; AnalyzeData; END; OnPostReport=BEGIN TempExcelBuf.DELETEALL; END; } DATASET { } REQUESTPAGE { PROPERTIES { SaveValues=Yes; OnQueryClosePage=VAR FileMgt@1001 : Codeunit 419; BEGIN IF CloseAction = ACTION::OK THEN BEGIN ServerFileName := FileMgt.UploadFile(Text006,ExcelFileExtensionTok); IF ServerFileName = '' THEN EXIT(FALSE); SheetName := TempExcelBuf.SelectSheetsName(ServerFileName); IF SheetName = '' THEN EXIT(FALSE); END; END; } CONTROLS { { 1900000001;0;Container; ContainerType=ContentArea } { 1900000002;1;Group ; CaptionML=[ENU=Options; ENG=Options] } } } LABELS { } CODE { VAR Text001@1005 : TextConst 'ENU=You must specify a %1 %2;ENG=You must specify a %1 %2'; Text002@1000000011 : TextConst 'ENU=You must specify a %1 for %2 %3;ENG=You must specify a %1 for %2 %3'; Text006@1006 : TextConst 'ENU=Import Excel File;ENG=Import Excel File'; Text007@1007 : TextConst 'ENU=Analyzing Data...\\;ENG=Analysing Data...\\'; TempExcelBuf@1027 : TEMPORARY Record 370; ServerFileName@1033 : Text; SheetName@1038 : Text[250]; TotalRowNo@1000000000 : Integer; RowNo@1000000001 : Integer; Window@1046 : Dialog; ExcelFileExtensionTok@1037 : TextConst '@@@={Locked};ENU=.xlsx;ENG=.xlsx'; LOCAL PROCEDURE AnalyzeData@2(); BEGIN //Did the user Import an empty Worksheet IF TempExcelBuf.ISEMPTY THEN EXIT; //Move to the last record TempExcelBuf.FINDLAST; //Assign the Total Rows to a Variable TotalRowNo := TempExcelBuf."Row No."; //Only imported the Column Captions IF TotalRowNo = 1 THEN EXIT; //Open a Window with a Progress bar Window.OPEN( Text007 + '@1@@@@@@@@@@@@@@@@@@@@@@@@@\'); Window.UPDATE(1,0); //Loop through the Rows FOR RowNo := 2 TO TotalRowNo DO BEGIN Window.UPDATE(1,ROUND(RowNo / TotalRowNo * 10000,1)); END; END; BEGIN END. } RDLDATA { } }