当前位置: 首页 > 图文教程 > 网络编程 > Javascript > javascript EXCEL 操作类代码

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 javascript EXCEL 操作类代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 299 ::
收藏到网摘: n/a

有空把JAVASCRIPT对EXCEL的操作进行了封装,大家可以根据自己实际的需要在此基础上进行扩充。详细的请看代码
复制代码 代码如下:

ExcelOperation = function(){
this.oXL = null;
this.oWB = null;
this.oSheet = null;
this.xlsRowCount = 0; //总记录数
this.excelFileName = null;
this.currentRow = 2; //当前行
/**
* 得到EXCEL表格中的总记录数
*/
this.getRowCount = function(){
//oSheet.Range("C1").Sort(oSheet.Columns("C"),xlAscending);
var rowsCount = this.oSheet.UsedRange.Cells.Rows.Count;
return rowsCount;
}
/**
* 按指定的列进行排序
* @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 : '请检查您的系统以下几方面的设置:1,'+
'是否正确安装了OFFICE中的EXCEL;2,正确设
置您的IE浏览器('+
'工具->internet选项->安全->internet->自定
义级别->'+
'启用“对没有标记为安全的ActiveX控件...”
);3,数据文件是否被删除',
buttons : Ext.Msg.OK,
icon : Ext.Msg.ERROR
});
return false;
}
}else{
Ext.Msg.show({
title : '错误提示',
msg : '请选择要导入的源数据文件!',
buttons : Ext.Msg.OK,
icon : Ext.Msg.ERROR
});
return false;
}
return this.oSheet;
}
/**
* 读取指定单元格的数据,
*/
this.readData = function(row,col){
var data = this.oSheet.Cells(row,col).Value;
if(typeof data == 'undefined')
return '';
else
return data;
}
/**
* 向指定单元格写入数据
*/
this.writeData = function(row,col,data){
this.oSheet.Cells(row,col) = data
}
/**
* 关闭EXCEL
*/
this.closeExcel = function(){
this.oXL.DisplayAlerts = false;
this.oXL.Quit();
this.oXL = null;
this.oWB=null;
this.oSheet=null;
CollectGarbage();
}
}