<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <script type="text/javascript"> function ReadExcel() { var tempStr = ""; //得到文件路径的值 var filePath = document.getElementById("upfile").value; //创建操作EXCEL应用程序的实例 var oXL = new ActiveXObject("Excel.application"); //打开指定路径的excel文件 var oWB = oXL.Workbooks.open(filePath); //操作第一个sheet(从一开始,而非零) oWB.worksheets(1).select(); var oSheet = oWB.ActiveSheet; //使用的行数 var rows = oSheet .usedrange.rows.count; try { for (var i = 2; i <= rows; 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.getElementById("txtArea").value = tempStr; } document.getElementById("txtArea").value = tempStr; //退出操作excel的实例对象 oXL.Application.Quit(); //手动调用垃圾收集器 CollectGarbage(); } </script> </head> <body> <input type="file" id="upfile" /><input type="button" onclick="ReadExcel();" value="read"> <br> <textarea id="txtArea" cols=50 rows=10></textarea> </body> </html>
转自 : http://blog.csdn.net/tongle_deng/article/details/7713572
来源:https://www.cnblogs.com/XiaoGer/archive/2012/12/31/2840861.html