如何将html里的table导出到Excel-CSDN论坛

如题所述

小子,你运气好,我刚做过,找了很久才找到个能用的。

<SCRIPT LANGUAGE="javascript">

<!--

function AutomateExcel() {

var elTable = document.getElementById("table1"); //table1改成你的tableID

var oRangeRef = document.body.createTextRange();

oRangeRef.moveToElementText(elTable);

oRangeRef.execCommand("Copy");

try {
var appExcel = new ActiveXObject("Excel.Application");
} catch (e) {
alert("无法调用Office对象,请确保您的机器已安装了Office并已将本系统的站点名加入到IE的信任站点列表中!");
return;
}

appExcel.Visible = true;

appExcel.Workbooks.Add().Worksheets.Item(1).Paste();

appExcel = null;

}

//-->

</SCRIPT>

调用

<input type="button" name="out_excel" onClick="AutomateExcel();" value="导出到excel" class="notPrint">
温馨提示:答案为网友推荐,仅供参考
相似回答