jsp页面把table导出为word 哥哥姐姐们!我想把一个jsp页面里的 table里的内容导出为word。该咋做啊!!在网上找了javascript。但是看不懂啊。也用不上。考下来用报错。能给我详细的javascript代码吗?直接考过来能用!!谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 javascript 没试过,java 里到是有jar 包可以做导成EXCEL如果你的页面是静态的,我觉得导出也没有太大意义,ctrl+s 保存网页就好了,如果是动态的数据,那就用java 导出好了 是动态的。你能说详细点吗?我做的是个科研申报系统。想把表格里的申报信息到出道word文档里。方便打印 导出到word和导出到excel是一个道理吧?我这里有导出到excel、需要的话加我Q;251637313 <html> <head> <title>projectGovPlace_list.jsp</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <link href="css/strongpt.css" rel="stylesheet" type="text/css"> </head> <body> <table width="100%" border="0" align="center" cellPadding="0" cellSpacing="0" id="datatable"> <tr align="center"> <td width="4%" class="table_title"> # </td> <td width="14%" class="table_title"> 项目 </td> </tr> <tr align="center" class="table_2"> <td align="center"> <input name="classId" value="8913" type="radio" /> </td> <td> <span>项目</span> </td> </tr> <tr align="center" class="table_1"> <td align="center"> <input name="classId" value="005" type="radio" /> </td> <td> <span>其他</span> </td> </tr> <tr align="center" class="table_2"> <td align="center"> <input name="classId" value="004" type="radio" /> </td> <td> <span>单位自筹</span> </td> </tr> <tr align="center" class="table_1"> <td align="center"> <input name="classId" value="003" type="radio" /> </td> <td> <span>银行贷款</span> </td> </tr> <tr align="center" class="table_2"> <td align="center"> <input name="classId" value="002" type="radio" /> </td> <td> <span>开行贷款</span> </td> </tr> <tr align="center" class="table_1"> <td align="center"> <input name="classId" value="001" type="radio" /> </td> <td> <span>市本级财政</span> </td> </tr> </table> <input type="button" onClick="return AutomateExcel();" value="导出到EXCEL" /> </br> <input type="button" onClick="return AllAreaWord();" value="导出到WORD" /> <script language="javascript"> function AutomateExcel(){ var elTable = document.getElementById("datatable"); //要导出的table id。 var oRangeRef = document.body.createTextRange(); oRangeRef.moveToElementText(elTable); oRangeRef.execCommand("Copy"); var appExcel = new ActiveXObject("Excel.Application"); appExcel.Workbooks.Add().Worksheets.Item(1).Paste(); appExcel.Visible = true; appExcel = null; } //导出到word //指定页面区域内容导入Word function AllAreaWord(){ var oWD = new ActiveXObject("Word.Application"); var oDC = oWD.Documents.Add("",0,1); var orange =oDC.Range(0,1); var elTable = document.getElementById("datatable"); var sel = document.body.createTextRange(); sel.moveToElementText(elTable); //sel.select(); sel.execCommand("Copy"); orange.Paste(); oWD.Application.Visible = true; oWD = null; } </script> </body></html> 这是网上找的。不能用啊!有哪位大哥能解释一下吗? 动态数据应该不太会有人用JS导出word,你这样的做法比较冷门,我是帮不了你了,你可以上网找一下java 导出的祝楼主好运吧 试了一下你的JS,new ActiveXObject这一行就报错了,你应该是缺少什么东西,你再确认一下你找的JS有没有漏掉吧,而且你的JS 中有 document.body 这种方式 好像是在 页面没有 DOCTYPE 声明时才可以使用的,如果有DOCTYPE 声明,则应该使用 document.documentElement 才可以 不会导为Word文档,只会导到Excel中,学学 网上搜一下有很多的,原理是调用word本身的复制命令,直接把页面的内容传进word,不过需要客户端装有word才行。我就是这样做的。 一般需要本地现装有word,并且把IE的安全级别调低一些(因为用到了控件)。 【高手进】Jfreechart如何实现如下这种功能 上传类型限制一定要继承 extends ActionSupport window.open()失效 应用服务器与WEB服务器 ant的时候出错 一个ibatis的问题 在java中如何使用安全认证(jaas) 问一简单问题!!!(分不够可以再加) 怎样使用JBUILDER 开发bmp。 哪位大神知道这是什么情况,急,在线求解 关于接口方法的实现问题 java 初学者
如果你的页面是静态的,我觉得导出也没有太大意义,ctrl+s 保存网页就好了,
如果是动态的数据,那就用java 导出好了
我这里有导出到excel、需要的话加我Q;251637313
<head>
<title>projectGovPlace_list.jsp</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link href="css/strongpt.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" align="center" cellPadding="0"
cellSpacing="0" id="datatable">
<tr align="center">
<td width="4%" class="table_title">
#
</td>
<td width="14%" class="table_title">
项目
</td>
</tr>
<tr align="center" class="table_2">
<td align="center">
<input name="classId" value="8913" type="radio" />
</td>
<td>
<span>项目</span>
</td>
</tr>
<tr align="center" class="table_1">
<td align="center">
<input name="classId" value="005" type="radio" />
</td>
<td>
<span>其他</span>
</td>
</tr>
<tr align="center" class="table_2">
<td align="center">
<input name="classId" value="004" type="radio" />
</td>
<td>
<span>单位自筹</span>
</td>
</tr>
<tr align="center" class="table_1">
<td align="center">
<input name="classId" value="003" type="radio" />
</td>
<td>
<span>银行贷款</span>
</td>
</tr>
<tr align="center" class="table_2">
<td align="center">
<input name="classId" value="002" type="radio" />
</td>
<td>
<span>开行贷款</span>
</td>
</tr>
<tr align="center" class="table_1">
<td align="center">
<input name="classId" value="001" type="radio" />
</td>
<td>
<span>市本级财政</span>
</td>
</tr>
</table>
<input type="button" onClick="return AutomateExcel();"
value="导出到EXCEL" />
</br>
<input type="button" onClick="return AllAreaWord();" value="导出到WORD" />
<script language="javascript">
function AutomateExcel(){
var elTable = document.getElementById("datatable"); //要导出的table id。
var oRangeRef = document.body.createTextRange();
oRangeRef.moveToElementText(elTable);
oRangeRef.execCommand("Copy");
var appExcel = new ActiveXObject("Excel.Application");
appExcel.Workbooks.Add().Worksheets.Item(1).Paste();
appExcel.Visible = true;
appExcel = null;
}
//导出到word
//指定页面区域内容导入Word
function AllAreaWord(){
var oWD = new ActiveXObject("Word.Application");
var oDC = oWD.Documents.Add("",0,1);
var orange =oDC.Range(0,1);
var elTable = document.getElementById("datatable");
var sel = document.body.createTextRange();
sel.moveToElementText(elTable);
//sel.select();
sel.execCommand("Copy");
orange.Paste();
oWD.Application.Visible = true;
oWD = null;
}
</script>
</body>
</html>
这是网上找的。不能用啊!有哪位大哥能解释一下吗?
我是帮不了你了,你可以上网找一下java 导出的
祝楼主好运吧
而且你的JS 中有 document.body 这种方式 好像是在 页面没有 DOCTYPE 声明时才可以使用的,如果有DOCTYPE 声明,则应该使用 document.documentElement 才可以