日期:2014-05-16  浏览次数:20445 次

如何把页面上的内容以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>