Static void nj_mf_test_exceliotest (ARGs _ ARGs)
{
Excelio IO;
# Excel
Dialogfield dialogfilename;
Dialog dialog = new dialog ("Excel upload ");
Container con;
;
Dialogfilename = dialog. addfield (typeid (filenameopen ));
Dialog. filenamelookuptitle ("upload from Excel ");
Dialog. filenamelookupfilter (["@ sys28576", # XLSX, "@ sys28576", # XLS]);
If (! Dialog. Run ())
Return;
IO = new excelio (dialogfilename. Value (), 'R ');
Setprefix ("Excel import ");
While (Io. Status () = io_status: OK)
{
Con = Io. Read ();
Info (con2str (CON ));
}
Io. Close (); // to quit Excel
}
-------------------------------------------------------------------
Exportfile for AOT version 1.0 or later
Formatversion: 1
* ** Element: CLS
; Microsoft Dynamics ax class: excelio udl extends t
;--------------------------------------------------------------------------------
Clsversion 1
Class # excelio
Properties
Name # excelio
Extends #
Runon # called from
Endproperties
Methods
Version: 3
Source # classdeclaration
# Class excelio
#{
# Sysexcelapplication application; // Excell Application
# Sysexcelcells cells; // Excell Cell Object
# Int maxrow; // Max number of rows, 1 based
# Int maxcol; // Max number of columns, 1 based
# Int currow; // current row number
#}
Endsource
Source # Close
# Public void close ()
#{
# If (Application)
# Application. Quit ();
#}
Endsource
Source # maxcol
# Public column maxcol ()
#{
# Return maxcol;
#}
Endsource
Source # maxrow
# Public row maxrow ()
#{
# Return maxrow;
#}
Endsource
Source # New
# Public void new (STR _ filename, STR _ Mode)
#{
# Sysexcelworkbooks workbooks;
# Sysexcelworksheets worksheets;
# Sysexcelworksheet worksheet;
# Com COM1, com2;
# File
#;
# Try
#{
# Application = sysexcelapplication: Construct ();
# Application. Visible (false );
# Workbooks = application. workbooks ();
# Workbooks. Open (_ filename, 0, _ mode = # io_read );
#
# Worksheets = workbooks. Item (1). worksheets ();
# Worksheet = worksheets. itemfromnum (1 );
# Cells = worksheet. cells ();
#
# COM1 = worksheet. comobject ();
# COM1 = com1.usedrange ();
# Com2 = com1.rows ();
# Maxrow = com2.count ();
#
# Com2 = com1.columns ();
# Maxcol = com2.count ();
#}
# Catch
#{
# Exceptiontextfallthrough ();
#}
#}
Endsource
Source # Read
# Public container read ()
#{
# Container ret;
# Int Col;
#;
# Currow ++;
# For (COL = 1; Col <= maxcol; Col ++)
#{
# RET + = new ccadofield (cells. Item (currow, col). comobject (). Value ();
#}
# Return ret;
#}
Endsource
Source # status
# Public io_status status ()
#{
# Return! Cells? Io_status: erroropen: currow <maxrow? Io_status: OK: io_status: filetooshort;
#}
Endsource
Source # writeexp
# Public Boolean writeexp (container _ data)
#{
# Throw error (error: wronguseoffunction (funcname ()));
#}
Endsource
Endmethods
Endclass
* ** Element: End