JavaScriptはページ表をExcelの具体的な実現としてエクスポートします.
3190 ワード
Excel
<br>var idTmr = "";
<br>function killExcelProcess(appExcel_){
<br>appExcel_.Quit();
<br>appExcel_ = null;
<br>idTmr = window.setInterval("Cleanup();",1);
<br>}
<br>
<br>// excel, tableid JSP table id, IE ,ActiveX , , “regsvr32 scrrun.dll”
<br>function exportToExcel(tableid,notitleandsearch){
<br>try {
<br>clipboardData.setData('Text','');
<br>var appExcel = new ActiveXObject("Excel.Application");
<br>
<br>killExcelProcess(appExcel);
<br>appExcel.workbooks.add;
<br>
<br>//
<br>if (notitleandsearch==null||notitleandsearch==false){
<br>var elTable = document.getElementById('div_title');
<br>var oRangeRef = document.body.createTextRange();
<br>oRangeRef.moveToElementText(elTable);
<br>oRangeRef.execCommand( "Copy" );
<br>appExcel.ActiveSheet.Cells(1,3).select();
<br>appExcel.ActiveSheet.Paste();
<br>
<br>clipboardData.setData('Text','');
<br>appExcel.ActiveSheet.Cells(2,1).select();
<br>appExcel.ActiveSheet.Paste();
<br>}
<br>
<br>var elTable1 = document.getElementById(tableid);
<br>var oRangeRef1 = document.body.createTextRange();
<br>oRangeRef1.moveToElementText(elTable1);
<br>oRangeRef1.execCommand( "Copy" );
<br>
<br>appExcel.WorkSheets(1).Activate;
<br>if (notitleandsearch==null||notitleandsearch==false){
<br>appExcel.ActiveSheet.Cells(3,1).select();
<br>}else{
<br>appExcel.ActiveSheet.Cells(1,1).select();
<br>}
<br>appExcel.WorkSheets(1).Activate;
<br>appExcel.ActiveSheet.Paste();
<br>appExcel.Visible = true;
<br>
<br>} catch(e) {
<br>alert(" IE ,ActiveX !");
<br>return false;
<br>}
<br>clipboardData.setData('text','');
<br>}
<br>
1
1
2
2
2
2
3
3
2
4
4
2
5
5
2
:
10