js 到处到 excel 很实用的代码 |
|
发起人:piaoling 回复数:0 浏览数:5772 最后更新:2009/12/25 10:21:06 by piaoling |
选择查看 | 搜索更多相关主题 帖子排序: |
piaoling 发表于 2009/12/25 10:21:06
|
js 到处到 excel 很实用的代码 <script language="javascript">
function tableToExcel() { //导入Excel window.clipboardData.setData("Text",document.all('theObjTable').outerHTML); try { var ExApp = new ActiveXObject("Excel.Application") var ExWBk = ExApp.workbooks.add() var ExWSh = ExWBk.worksheets(1) ExApp.DisplayAlerts = false ExApp.visible = true ExWSh.Columns("A:A").ColumnWidth = 7 //根据具体情况设置行宽 ExWSh.Columns("B:B").ColumnWidth = 19 ExWSh.Columns("C:C").ColumnWidth = 40 ExWSh.Columns("D:D").ColumnWidth = 20 ExWSh.Columns("E:E").ColumnWidth = 23 ExWSh.Columns("F:F").ColumnWidth = 7 ExWSh.Rows("1:1").RowHeight = 79.5 //根据具体情设置行高 ExWSh.Rows("2:2").RowHeight = 84 ExWSh.Rows("3:3").RowHeight = 36.75 ExWSh.Rows("4:4").RowHeight = 75 ExWSh.Rows("5:5").RowHeight = 30 ExWSh.Rows("6:6").RowHeight = 30 ExWSh.Rows("7:7").RowHeight = 30 ExWSh.PageSetup.Orientation = 2 //设置页面方向,1为纵向,2为横向 } catch(e){ alert("您的电脑没有安装Microsoft Excel软件!") return false } ExWBk.worksheets(1).Paste; } </script> <input type="button" name="Submit" value="导出到Excel" onclick="javascript:tableToExcel()"> //导出按钮 <table width="855" border="0" align="center" cellpadding="0" cellspacing="0" id="theObjTable"> //具体要到到Excel的表格对象 |
返回页首↑ |