日期:2014-05-16 浏览次数:20467 次
<script language="javascript" type="text/javascript"><!-- function readExcel() { var excelApp; var excelWorkBook; var excelSheet; try{ excelApp = new ActiveXObject("Excel.Application"); excelWorkBook = excelApp.Workbooks.open("C:\\XXX.xls"); excelSheet = oWB.ActiveSheet; //WorkSheets("sheet1") excelSheet.Cells(6,2).value;//cell的值 excelSheet.usedrange.rows.count;//使用的行数 excelWorkBook.Worksheets.count;//得到sheet的个数 excelSheet=null; excelWorkBook.close(); excelApp.Application.Quit(); excelApp=null; }catch(e){ if(excelSheet !=null || excelSheet!=undefined){ excelSheet =nul; } if(excelWorkBook != null || excelWorkBook!=undefined){ excelWorkBook.close(); } if(excelApp != null || excelApp!=undefined){ excelApp.Application.Quit(); excelApp=null; } } // --></script>
<script> function ReadExcel() { var tempStr = ""; var filePath= document.all.upfile.value; var oXL = new ActiveXObject("Excel.application"); var oWB = oXL.Workbooks.open(filePath); oWB.worksheets(1).select(); var oSheet = oWB.ActiveSheet; try{ for(var i=2;i<46;i++) { if(oSheet.Cells(i,2).value =="null" || oSheet.Cells(i,3).value =="null" ) break; var a = oSheet.Cells(i,2).value.toString()=="undefined"?"":oSheet.Cells(i,2).value; tempStr+=(" "+oSheet.Cells(i,2).value+ " "+oSheet.Cells(i,3).value+ " "+oSheet.Cells(i,4).value+ " "+oSheet.Cells(i,5).value+ " "+oSheet.Cells(i,6).value+"\n"); } }catch(e) { document.all.txtArea.value = tempStr; } document.all.txtArea.value = tempStr; oXL.Quit(); CollectGarbage(); } </script> <html> <input type="file" id="upfile" /><input type="button" onclick="ReadExcel();" value="read"> <br> <textarea id="txtArea" cols=50 rows=10></textarea> </html>
<script> function readThis(){ var tempStr = ""; var filePath= document.all.upfile.value; var oXL = new ActiveXObject("Excel.application"); var oWB = oXL.Workbooks.open(filePath); oWB.worksheets(1).select(); var oSheet = oWB.ActiveSheet; try{ for(var i=2;i<46;i++){ if(oSheet.Cells(i,2).value =="null" || oSheet.Cells(i,3).value =="null" ) break; var a = oSheet.Cells(i,2).value.toString()=="undefined"?"":oSheet.Cells(i,2).value; tempStr+=(" "+oSheet.Cells(i,2).value+" "+oSheet.Cells(i,3).value+" "+oSheet.Cells(i,4).value+" "+oSheet.Cells(i,5).value+" "+oSheet.Cells(i,6).value+"\n"); } } catch(e){ //alert(e); document.all.txtArea.value = tempStr; } document.all.txtArea.value = tempStr; oXL.Quit(); CollectGarbage(); } </script> <html> <input type="file" id="upfile" /> <input type="button" onclick="readThis();" value="读取"><br> <textarea id="txtArea" cols=50 rows=10></textarea> </html>
function readExcel() { try { var ExcelNum=new Array(); //重复导入之前,删除上次导入的同期数据 WebServiceExcel.deleteOldNumber(); var oXL = new ActiveXObject( "Excel.Application "); \\r_c_num[5]的值为excel文件的名字 var path=document.all.excelpath.value+ "\\ "+r_c_num[5] var oWB = oXL.Workbooks.open(path); \\如果excel文件有多个sheet的话从第一个sheet循环读取 for(var x=1;x <=oWB.worksheets.count;x++) { oWB.worksheets(x).select(); var oSheet =oWB.ActiveSheet; \\按指定开始行和开始列读取excel文件的数据 for(var i=parseInt(r_c_num[6]);i <=parseInt(r_c_num[7]);i++) { for(var j=parseInt(r_c_num[8]);j <=parseI