Javascript EXCEL operation code

Source: Internet
Author: User

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 ();
}
}

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.