当前位置: 代码迷 >> JavaScript >> 怎么把页面上的内容以excel的格式导出
  详细解决方案

怎么把页面上的内容以excel的格式导出

热度:142   发布时间:2012-02-19 19:43:39.0
如何把页面上的内容以excel的格式导出?
比如我有一个list,里边有考生的姓名,班级,成绩等等,如何把这个list以excel的格式导出?

------解决方案--------------------
<table width= "100% " border= "1 " cellspacing= "0 " cellpadding= "0 " bgcolor = "#61FF13 ">
<TR style= "text-align : center; ">
<TD> 单元格A </TD>
<TD> 单元格A </TD>
<TD> 单元格A </TD>
<TD> 单元格A </TD>
</TR>
<TR>
<TD colSpan=4 style= "text-align : center; "> <font color= "BLUE " face= "Verdana "> 单元格合并行A </FONT> </TD>
</TR>
</TABLE>
<BR>
<table width= "100% " border= "1 " cellspacing= "0 " cellpadding= "0 ">
<TR style= "text-align : center; ">
<TD> 单元格B </TD>
<TD> 单元格B </TD>
<TD> 单元格B </TD>
<TD> 单元格B </TD>
</TR>
<TR>
<TD colSpan=4 style= "text-align : center; "> 单元格合并行B </TD>
</TR>
</TABLE>
<br> <br> <br>
<input type= "button " onclick= "javascript:AllAreaExcel(); " value= "导出页面内容到Excel ">
<SCRIPT LANGUAGE= "javascript ">
function AllAreaExcel()
{
var oXL = new ActiveXObject( "Excel.Application ");
var oWB = oXL.Workbooks.Add();
for(i = 0;i <document.getElementsByTagName( "TABLE ").length;i++)
{
oSheet = oWB.Worksheets.Add();
sel=document.body.createTextRange();
sel.moveToElementText(document.getElementsByTagName( "TABLE ")[i]);
sel.select();
sel.execCommand( "Copy ");
oSheet.Paste();
}

oXL.Visible = true;
}


</SCRIPT>
</body>
</html>
  相关解决方案