Copy Code code as follows:
Exceloperation = function () {
THIS.OXL = null;
THIS.OWB = null;
This.osheet = null;
This.xlsrowcount = 0; Total number of records
This.excelfilename = null;
This.currentrow = 2; When moving forward
/**
* Get 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 the 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,null,null,null,null,xlyes,null,null,
Xlsortrows,xlpinyin,xlsortnormal,null,null);
}
/**
* Open an Excel
*/
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.xlsrowcount = This.getrowcount ();
}catch (e) {
if (THIS.OXL)
This.closeexcel ();
Ext.Msg.show ({
Title: ' False hint ',
Msg: ' Please check your system for the following settings: 1, ' +
' properly installed excel;2 in office, correctly set
Placing your IE browser (' +
' Tool->internet option-> security->internet-> self-setting
Semantic level-> ' +
' Enable ' for ActiveX controls that are not marked as safe ... '
3, whether the data file was deleted ',
Buttons:Ext.Msg.OK,
Icon:Ext.Msg.ERROR
});
return false;
}
}else{
Ext.Msg.show ({
Title: ' False hint ',
msg: ' Please select the source data file to import! ',
Buttons:Ext.Msg.OK,
Icon:Ext.Msg.ERROR
});
return false;
}
return this.osheet;
}
/**
* Read the data for the 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 the 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 ();
}
}