この記事では、WebページのコンテンツをWordとExcelにエクスポートするJavaScriptの方法について説明します。参照のためにそれを共有してください。特定の実装方法は次のとおりです。
<html> <head> <title> excelドキュメントとしてウェブページをエクスポートする方法</title> </head> <body> <body id = "printa" cellpacing = "0" cellpadding = "0" bgcolor = "#61ff13"> 61ff13 "> <tr style =" a </td> </tr> <tr> <td colspan = 4 style = "text-align:center;"> <font color = "blue" face = "verdana">セルマージ行A </font> </td> </tr </table> <br> <br> <table id = "printb" cellpacing = "中心; "> <td>セルB </td> <td>セルB </td> <td>セルB </td> </tr> <tr> <td colspan = 4 style =" text-align:center; ">セルマージb </td> </tr> </table> <br> <br> <input =" butn value = "exportページ指定されたエリアコンテンツをWord"> <input type = "button" onclick = "javascript:allareaxcel();" value = "Export Page指定された領域コンテンツをExcel"> <input type = "button" onclick = "javascript:cellareaxcel();" value = "excel to excelにフォームセルコンテンツをエクスポート"> <script言語= "javascript"> //ページ領域コンテンツをExcelfunction allareaxcel(){var oxl = new ActiveXObject( "excel.Application"); var owb = oxl.workbooks.add(); var osheet = owb.activesheet; var sel = document.body.createTextrange(); sel.movetoelementText(printa); sel.select(); sel.execcommand( "copy"); osheet.paste(); oxl.visible = true;} //ページエリア "セルの指定"セル "cell = excelfunction cellaexcel() var owb = oxl.workbooks.add(); var osheet = owb.activesheet; var lenr = printa.rows.length; for(i = 0; i <lenr; i ++){var lenc = printa.rows(i).cells.length; for(j = 0; j <lenc; j ++){osheet.cells(i+1、j+1).value = printa.rows(i).cells(j).innertext; }} oxl.visible = true; } //指定されたページ領域のコンテンツをインポートします。 wordfunction allareaword(){var owd = new ActiveXObject( "word.application"); var odc = owd.documents.add( ""、0,1); var orange = odc.range(0,1); var sel = document.body.createTextrange(); sel.movetoelementText(printa); sel.select(); sel.execcommand( "copy"); orange.paste(); owd.application.visible = true; // window.close();} </script> </html>この記事がみんなのJavaScriptプログラミングに役立つことを願っています。