日期:2014-05-16 浏览次数:20448 次
function read(){ var path=document.form1.file.value; var sheets=document.getElementById("sheets").value; if(sheets==""){ alert("请输入sheet"); }else{ var sheet=parseInt(sheets); var tempStr = "<table border='1' id='tblid'>"; var oXL = new ActiveXObject("Excel.application"); var oWB = oXL.Workbooks.open(path); oWB.worksheets(sheet).select(); var oSheet = oWB.ActiveSheet; var rowcount=oWB.Worksheets(sheet).UsedRange.Cells.Rows.Count; var colcount=oWB.Worksheets(sheet).UsedRange.Cells.Columns.Count; try{ var s=0; for(var i=1;i<=rowcount;i++){ tempStr+="<tr>"; for(var j=1;j<=colcount;j++){ //tempStr+=(oSheet.Cells(i,j).value+" "); var vl=oSheet.Cells(i,j).value; //alert(vl); if(typeof(vl) == "undefined"){ tempStr+="<td>"; tempStr+="<input value='' id=tbl"+(s++)+" />"; tempStr+="</td>"; }else{ tempStr+="<td>"; tempStr+="<input value="+vl+" id=tbl"+(s++)+" />"; tempStr+="</td>"; //alert(s++); } } tempStr+="</tr><br>"; } tempStr+="</table>"; document.getElementById("div").innerHTML = tempStr; }catch(e){ //alert(e); document.all.div.value = tempStr; } oXL.Quit(); CollectGarbage(); } }