JavaScript EXCEL operation class Code _javascript tips

Source: Internet
Author: User
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 ();
}
}

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.