function show_saveAs(){
CommonDialog1.InitDir=location.href.replace(/file\:\/\/\//ig,"").replace(/\//g,"\\");
CommonDialog1.Filter="*.xls|*.xls|"
CommonDialog1.FileName=""
CommonDialog1.ShowSave();
if(CommonDialog1.FileName.length==0){
return;
} else{
var AppExcel,AppBook,fso,filePointer,oTable,arrValue1,arrValue2;
var strTemp="";
oTable=document.getElementsByTagName("table")[0];
fso=new ActiveXObject("Scripting.FileSystemObject");
if(fso.FileExists(CommonDialog1.FileName)){
if(!confirm("该文件已经存在,你想覆盖掉吗?")){
return;
}
}
fso.createTextFile(CommonDialog1.FileName);
AppExcel=new ActiveXObject("Excel.Application");
AppBook=AppExcel.workbooks.open(CommonDialog1.FileName);
for(var i=0;i<oTable.rows.length;i++){
for(var j=0;j<oTable.rows[i].cells.length;j++)
strTemp+=oTable.rows[i].cells[j].firstChild.value+",";
strTemp+="\n";
}
arrValue1=strTemp.split(",\n");
try{
for(var k=0;k<arrValue1.length-1;k++){
arrValue2=arrValue1[k].split(",");
for(var num=0;num<arrValue2.length;num++)
AppBook.worksheets(1).cells(k+1,num+1).value=arrValue2[num];
}
}
catch(e){alert(e.message);}
finally{
AppBook.save();
AppBook.close(true);
AppBook=null;
AppExcel.quit();
AppExcel=null;
alert("\t\t保存成功!\n\n这只是一个例子,你把你自己的表格加上去就行了!");
}
}
}
</script>
IE中提示"对象不支持此属性或方法"
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货