javascript EXCEL 操作類代碼
更新時間:2009年07月30日 17:31:54 作者:
有空把JAVASCRIPT對EXCEL的操作進(jìn)行了封裝,大家可以根據(jù)自己實(shí)際的需要在此基礎(chǔ)上進(jìn)行擴(kuò)充。詳細(xì)的請看代碼
復(fù)制代碼 代碼如下:
ExcelOperation = function(){
this.oXL = null;
this.oWB = null;
this.oSheet = null;
this.xlsRowCount = 0; //總記錄數(shù)
this.excelFileName = null;
this.currentRow = 2; //當(dāng)前行
/**
* 得到EXCEL表格中的總記錄數(shù)
*/
this.getRowCount = function(){
//oSheet.Range("C1").Sort(oSheet.Columns("C"),xlAscending);
var rowsCount = this.oSheet.UsedRange.Cells.Rows.Count;
return rowsCount;
}
/**
* 按指定的列進(jìn)行排序
* @param column 列名,如"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);
}
/**
* 打開一個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 : '錯誤提示',
msg : '請檢查您的系統(tǒng)以下幾方面的設(shè)置:1,'+
'是否正確安裝了OFFICE中的EXCEL;2,正確設(shè)
置您的IE瀏覽器('+
'工具->internet選項(xiàng)->安全->internet->自定
義級別->'+
'啟用“對沒有標(biāo)記為安全的ActiveX控件...”
);3,數(shù)據(jù)文件是否被刪除',
buttons : Ext.Msg.OK,
icon : Ext.Msg.ERROR
});
return false;
}
}else{
Ext.Msg.show({
title : '錯誤提示',
msg : '請選擇要導(dǎo)入的源數(shù)據(jù)文件!',
buttons : Ext.Msg.OK,
icon : Ext.Msg.ERROR
});
return false;
}
return this.oSheet;
}
/**
* 讀取指定單元格的數(shù)據(jù),
*/
this.readData = function(row,col){
var data = this.oSheet.Cells(row,col).Value;
if(typeof data == 'undefined')
return '';
else
return data;
}
/**
* 向指定單元格寫入數(shù)據(jù)
*/
this.writeData = function(row,col,data){
this.oSheet.Cells(row,col) = data
}
/**
* 關(guān)閉EXCEL
*/
this.closeExcel = function(){
this.oXL.DisplayAlerts = false;
this.oXL.Quit();
this.oXL = null;
this.oWB=null;
this.oSheet=null;
CollectGarbage();
}
}
您可能感興趣的文章:
- 用javascript將數(shù)據(jù)導(dǎo)入Excel示例代碼
- javascript操作excel生成報表示例
- javascript操作excel生成報表全攻略
- 通過Javascript讀取本地Excel文件內(nèi)容的代碼示例
- 通過復(fù)制Table生成word和excel的javascript代碼
- JavaScript將頁面表格導(dǎo)出為Excel的具體實(shí)現(xiàn)
- JavaScript將Table導(dǎo)出到Excel實(shí)現(xiàn)思路及代碼
- javascript 操作Word和Excel的實(shí)現(xiàn)代碼
- javascript Excel操作知識點(diǎn)
- Javascript客戶端將指定區(qū)域?qū)С龅絎ord、Excel的代碼
- JavaScript導(dǎo)出Excel實(shí)例詳解
相關(guān)文章
簡單談?wù)刯avascript中的變量、作用域和內(nèi)存問題
這篇文章主要介紹了簡單談?wù)刯avascript中的變量、作用域和內(nèi)存問題的相關(guān)資料,需要的朋友可以參考下2015-08-08
JS繼承與閉包及JS實(shí)現(xiàn)繼承的三種方式
大家都知道,面向?qū)ο蟮娜筇卣鳌庋b、繼承、多態(tài)。下面通過本文給大家介紹JS繼承與閉包及JS實(shí)現(xiàn)繼承的三種方式,感興趣的朋友一起看看吧2017-10-10
微信小程序防止多次點(diǎn)擊跳轉(zhuǎn)和防止表單組件輸入內(nèi)容多次驗(yàn)證功能(函數(shù)防抖)
這篇文章主要介紹了微信小程序防止多次點(diǎn)擊跳轉(zhuǎn)和防止表單組件輸入內(nèi)容多次驗(yàn)證功能(函數(shù)防抖),需要的朋友可以參考下2019-09-09
Javascript節(jié)點(diǎn)關(guān)系實(shí)例分析
這篇文章主要介紹了Javascript節(jié)點(diǎn)關(guān)系,實(shí)例分析了javascript操作父子節(jié)點(diǎn)及兄弟節(jié)點(diǎn)的相關(guān)技巧,需要的朋友可以參考下2015-05-05
基于JS實(shí)現(xiàn)導(dǎo)航條flash導(dǎo)航條
flash導(dǎo)航條在網(wǎng)站建設(shè)中應(yīng)用比較廣泛,此種效果給瀏覽者帶來極好的視覺效果,非常棒,下面小編給大家介紹基于JS實(shí)現(xiàn)導(dǎo)航條flash導(dǎo)航條,非常不錯,具有參考借鑒價值,感興趣的朋友一起學(xué)習(xí)吧2016-06-06

