Use excelio operations to read Excel files

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.