js读取excel文档记录...
时间:2010-08-17 来源:paopao00o
首先必须将浏览器 工具-internet选项-安全 信用站点添加进去 如:http://localhost添加进去 再将 区域安全级别设为“低” 执行程序是 选择下载插件就OK了
程序:
/**
* 拼装导入数据二元数组
* @param {} filepath
* @return {}
*/
this.readExcel=function ()
{
try
{
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.open("C:\\Documents and Settings\\zhangc\\桌面\\通讯录导入模板.xls");
}catch(e)
{
alert('打开文件失败!');
}
var oSheet = oWB.ActiveSheet;
var exceldata=new Array(oSheet.usedrange.rows.count-3);
for(i=4;i<=oSheet.usedrange.rows.count;i++)
{
var datavalue=new Array(29);
datavalue[0]=this.groupid;
datavalue[1]=oSheet.Cells(i,1).value;
datavalue[2]=oSheet.Cells(i,2).value;
datavalue[3]=oSheet.Cells(i,3).value;
datavalue[4]=oSheet.Cells(i,4).value;
datavalue[5]=oSheet.Cells(i,5).value;
datavalue[6]=oSheet.Cells(i,6).value;
datavalue[7]=oSheet.Cells(i,7).value;
datavalue[8]=oSheet.Cells(i,8).value;
datavalue[9]=oSheet.Cells(i,9).value;
datavalue[10]=oSheet.Cells(i,10).value;
datavalue[11]=oSheet.Cells(i,11).value;
datavalue[12]=oSheet.Cells(i,12).value;
datavalue[13]=oSheet.Cells(i,13).value;
datavalue[14]=oSheet.Cells(i,14).value;
datavalue[15]=oSheet.Cells(i,15).value;
datavalue[16]=oSheet.Cells(i,16).value;
datavalue[17]=oSheet.Cells(i,17).value;
datavalue[18]=oSheet.Cells(i,18).value;
datavalue[19]=oSheet.Cells(i,19).value;
datavalue[20]=oSheet.Cells(i,20).value;
datavalue[21]=oSheet.Cells(i,21).value;
datavalue[22]=oSheet.Cells(i,22).value;
datavalue[23]=oSheet.Cells(i,23).value;
datavalue[24]=oSheet.Cells(i,24).value;
datavalue[25]="";
datavalue[26]=LEAP.userInfo.userflag;
datavalue[27]=LEAP.userInfo.positionid;
datavalue[28]='';//LEAP.request('getTopOrgID');
exceldata[i]=datavalue;
}
oSheet=null;
oWB.close();
oXL=null;
return exceldata;
}
还须根据Excel文档格式自行调整循环i值