Copy codeThe Code is as follows:
ExcelOperation = function (){
This. oXL = null;
This. oWB = null;
This. oSheet = null;
This.xls RowCount = 0; // total number of records
This. excelFileName = null;
This. currentRow = 2; // current row
/**
* Obtain the total number of records in the EXCEL table.
*/
This. getRowCount = function (){
// OSheet. Range ("C1"). Sort (oSheet. Columns ("C"), xlAscending );
Var rowsCount = this. oSheet. UsedRange. Cells. Rows. Count;
Return rowsCount;
}
/**
* Sort by specified Column
* @ Param column name, such as "C"
*/
This. sort = function (column ){
Var xlAscending = 1;
Var xlYes = 1;
Var xlSortRows = 1;
Var xlPinYin = 1;
Var xlSortNormal = 1;
This. oSheet. UsedRange. Sort (this. oSheet. Columns (column ),
XlAscending, null, xlYes, null, null,
XlSortRows, xlPinYin, xlSortNormal, null, null );
}
/**
* Open an EXCEL file
*/
This. openExcel = function (fileName ){
This. fileName = fileName;
If (this. fileName ){
Try {
This. oXL = new ActiveXObject ("Excel. application ");
This. oWB = this. oXL. Workbooks. open (fileName );
// "E: \ join.xls"
This. oWB. worksheets (1). select ();
This. oSheet = this. oWB. ActiveSheet;
This.xls RowCount = this. getRowCount ();
} Catch (e ){
If (this. oXL)
This. closeExcel ();
Ext. Msg. show ({
Title: 'error message ',
Msg: 'check the following settings of your system: 1, '+
'Are the EXCEL files in OFFICE correctly installed? 2. Correct settings
Set your IE browser ('+
'Tools-> internet Options-> Security-> internet-> Custom
Level of definition-> '+
'Enable "for ActiveX controls that are not marked as secure ..."
); 3. Whether the data file is deleted ',
Buttons: Ext. Msg. OK,
Icon: Ext. Msg. ERROR
});
Return false;
}
} Else {
Ext. Msg. show ({
Title: 'error message ',
Msg: 'select the source data file to import! ',
Buttons: Ext. Msg. OK,
Icon: Ext. Msg. ERROR
});
Return false;
}
Return this. oSheet;
}
/**
* Read the data of a specified cell,
*/
This. readData = function (row, col ){
Var data = this. oSheet. Cells (row, col). Value;
If (typeof data = 'undefined ')
Return '';
Else
Return data;
}
/**
* Write data to a specified Cell
*/
This. writeData = function (row, col, data ){
This. oSheet. Cells (row, col) = data
}
/**
* Close EXCEL
*/
This. closeExcel = function (){
This. oXL. DisplayAlerts = false;
This. oXL. Quit ();
This. oXL = null;
This. oWB = null;
This. oSheet = null;
CollectGarbage ();
}
}