网页表格导出到word
答案:3 悬赏:20 手机版
解决时间 2021-01-24 17:35
- 提问者网友:玫瑰园
- 2021-01-24 08:18
怎么把网页中某个表格中的一个单元格内容导出到一个一个指定的word文档中,跪求详细代码
最佳答案
- 五星知识达人网友:低血压的长颈鹿
- 2021-01-24 09:11
function jscomExportTableToWord(tableName)<br> {<br> if(document.all(tableName).rows.length==0)<br> {<br> alert("没有内容可导!");<br> return;<br> }<br><br> var oWord;<br> try{<br> oWord = new ActiveXObject("Word.Application"); // Get a new workbook.<br> }catch(e)<br> {<br> alert("无法调用Office对象,请确保您的机器已安装了Office并已将本系统的站点名加入到IE的信任站点列表中!");<br> return;<br> }<br> var oDocument = oWord.Documents.Add();<br> var oDocument = oWord.ActiveDocument; <br> //oDocument.Paragraphs.Add();<br> oDocument.Paragraphs.Last.Alignment = 1;<br> oDocument.Paragraphs.Last.Range.Bold = true;<br> oDocument.Paragraphs.Last.Range.Font.Size = 16;<br> oDocument.Paragraphs.Last.Range.Font.name = "宋体";<br> oDocument.Paragraphs.Last.Range.InsertAfter(document.all("lblTitle").innerText);<br><br> oDocument.Paragraphs.Add();<br> oDocument.Paragraphs.Last.Alignment = 2;<br> oDocument.Paragraphs.Last.Range.Bold = false;<br> oDocument.Paragraphs.Last.Range.Font.Size = 12;<br> oDocument.Paragraphs.Last.Range.Font.name = "宋体";<br> oDocument.Paragraphs.Last.Range.InsertAfter(document.all("lblSubTitle").innerText);<br><br> var table = document.all(tableName);<br> var nRows = table.rows.length; <br> var nCols = table.rows(0).cells.length;<br> for (i=0;i<nRows;i++)<br> {<br> nCol=0;<br> nCols=table.rows(i).cells.length;<br> for (j=0;j<nCols;j++) <br> { <br> if(table.rows(i).cells(j))<br> {<br> oDocument.Paragraphs.Add();<br> oDocument.Paragraphs.Last.Alignment = 0;<br> oDocument.Paragraphs.Last.Range.Bold =false;<br> if(j==0)<br> oDocument.Paragraphs.Last.Range.Font.Size = 14;<br> else<br> oDocument.Paragraphs.Last.Range.Font.Size = 10;<br> oDocument.Paragraphs.Last.Range.Font.name = "宋体";<br> oDocument.Paragraphs.Last.Range.InsertAfter(table.rows(i).cells(j).innerText);<br> }<br> nCol=nCol+1;<br> } <br> }<br> oWord.Visible = true;<br> }
全部回答
- 1楼网友:风格不统一
- 2021-01-24 11:30
jsp输出word
在页面直接打开word。
在action中写
response.reset();
response.setcontenttype("application/msword;charset=gbk");
response.setheader("content-disposition", "inline;filename=temp.doc");
response.getoutputstream().write(document.getcontent());
response.getoutputstream().flush();
response.getoutputstream().close();
return null;
在页面时下载word。
在action中写
response.reset();
response.setcontenttype("application/x-download;charset=gbk");
response.setheader("content-disposition", "attachment;filename=temp.doc");
response.getoutputstream().write(document.getcontent());
response.getoutputstream().flush();
response.getoutputstream().close();
return null;
- 2楼网友:第幾種人
- 2021-01-24 10:27
这个不用代码页可以实现的,直接选择并且导出为doc文档就可以了。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯