<Script Language="VbScript">
<!--
Set oExcel=CreateObject("Excel.Application")
'oExcel.Visible = True
oExcel.Workbooks.Open "C:\Documents and Settings\Administrator\桌面\测试用Excel\2.xls"
oExcel.Workbooks(1).Activate
oExcel.Sheets(1).Select
document.write("<Table Border=1 Width=98% Align=Center>")
For R = 1 To oExcel.Cells.CurrentRegion.Rows.Count
document.write("<Tr>")
For C = 1 To oExcel.Cells.CurrentRegion.Columns.Count
document.writeln("<Td>" & oExcel.Cells(R, C).Value & "&nbsp;</Td>")
Next 
document.write("</Tr>")
Next 
document.write("</Table>")
oExcel.ActiveWorkBook.Close False
oExcel.Quit 
Set oExcel=Nothing
 -->
</Script>

解决方案 »

  1.   

    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function table2array(table1) //把一个表格转换为一个2维数组
    {
    return tbody2array(table1.firstChild)
    }function tbody2array(tbody1)
    {
    var elm=tbody1.children;
    var result = new Array();
    for (var i=0;i<elm.length;i++)
    {
    var tmp = new Array(); for (var j=0;j<elm[i].children.length;j++)
    tmp[tmp.length] = elm[i].children[j].innerText;
    result [result.length]=tmp;
    }
    return (result);
    }//-->
    </SCRIPT></HEAD><BODY><table id="resultRs" BORDER="0" CELLSPACING="1" CELLPADDING="1" WIDTH="100%" BGCOLOR="#999999">
    <tr BGCOLOR="#d8c8a8">                                  
    <td ALIGN="CENTER" width="1%" NOWRAP CLASS="ttTable">序号</td>            
        <td ALIGN="CENTER" NOWRAP CLASS="ttTable">客户名称</td>
    <td ALIGN="CENTER" NOWRAP CLASS="ttTable">6月</td>
    <td ALIGN="CENTER" NOWRAP CLASS="ttTable">7月</td>
    <td ALIGN="CENTER" NOWRAP CLASS="ttTable">8月</td>
    <td ALIGN="CENTER" NOWRAP CLASS="ttTable">总计</td>
    </tr>
    <tr BGCOLOR="#f0f0e8">
    <td NOWRAP class="td">1</td>
    <td NOWRAP class="td">建丰广州公司</td>
      
                      <td ALIGN="right" class="td" NOWRAP></td>
                       
                      <td ALIGN="right" class="td" NOWRAP>528,343</td>
                       
                      <td ALIGN="right" class="td" NOWRAP></td>
                    
      <td ALIGN="right" class="td" NOWRAP>528,343</td>
      
                   </tr>
                   

    <tr BGCOLOR="#f8f4e4">
    <td NOWRAP class="td">2</td>
    <td NOWRAP class="td">大地科技技术有限公司</td>
      
                      <td ALIGN="right" class="td" NOWRAP></td>
                       
                      <td ALIGN="right" class="td" NOWRAP>137,440</td>
                       
                      <td ALIGN="right" class="td" NOWRAP>248,990</td>
                    
      <td ALIGN="right" class="td" NOWRAP>386,430</td>
      
                   </tr>
                   

    <tr BGCOLOR="#f0f0e8">
    <td NOWRAP class="td">3</td>
    <td NOWRAP class="td">滁州亿万饲料科技有限公司</td>
      
                      <td ALIGN="right" class="td" NOWRAP>300,000</td>
                       
                      <td ALIGN="right" class="td" NOWRAP></td>
                       
                      <td ALIGN="right" class="td" NOWRAP></td>
                    
      <td ALIGN="right" class="td" NOWRAP>300,000</td>
      
                   </tr>
                   

    <tr BGCOLOR="#f8f4e4">
    <td NOWRAP class="td">4</td>
    <td NOWRAP class="td">合肥华仁生物技术有限公司</td>
      
                      <td ALIGN="right" class="td" NOWRAP>300,000</td>
                       
                      <td ALIGN="right" class="td" NOWRAP></td>
                       
                      <td ALIGN="right" class="td" NOWRAP></td>
                    
      <td ALIGN="right" class="td" NOWRAP>300,000</td>
      
                   </tr>
                   

    <tr BGCOLOR="#f0f0e8">
    <td NOWRAP class="td">5</td>
    <td NOWRAP class="td">福建龙岩佳明畜牧饲料有限公司</td>
      
                      <td ALIGN="right" class="td" NOWRAP>252,500</td>
                       
                      <td ALIGN="right" class="td" NOWRAP>1,250</td>
                       
                      <td ALIGN="right" class="td" NOWRAP></td>
                    
      <td ALIGN="right" class="td" NOWRAP>253,750</td>
      
                   </tr>
                   

     <tr BGCOLOR="#d8c8a8">
    <td NOWRAP class="td"></td>
    <td NOWRAP class="td">合计</td>

                      <td ALIGN="right" class="td" NOWRAP>852,500</td>
                    
                      <td ALIGN="right" class="td" NOWRAP>667,033</td>
                    
                      <td ALIGN="right" class="td" NOWRAP>248,990</td>
                    
      <td ALIGN="right" class="td" NOWRAP>1,768,523</td>   
                   </tr>

    </table>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var arRS = table2array(resultRs);
    //-->
    </SCRIPT>
    <INPUT TYPE="button" value="showExcel" onclick="showExcel(arRS,'客户交易排行');">
    <SCRIPT LANGUAGE="JavaScript">
    <!--function showExcel(ar,title){
    var s_head="<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\">"
    +"<head><style type=\"text/css\">"
    +"<!--"
    +"tr {mso-height-source:auto;}"
    +"td {white-space:nowrap;}"
    +".wcC24FAB9 {white-space:nowrap;font-family:宋体;mso-number-format:General;font-size:auto;font-weight:auto;font-style:auto;text-decoration:auto;mso-background-source:auto;mso-pattern:auto;mso-color-source:auto;text-align:general;vertical-align:bottom;border-top:none;border-left:none;border-right:none;border-bottom:none;mso-protection:locked;}"
    +".wcCF5FAB9 {white-space:nowrap;font-family:宋体;mso-number-format:General;font-size:auto;font-weight:auto;font-style:auto;text-decoration:auto;mso-background-source:auto;mso-pattern:auto;mso-color-source:auto;text-align:general;vertical-align:bottom;border-top:none;border-left:none;border-right:none;border-bottom:none;mso-protection:unlocked;}"
    +"-->"
    +"</style></head><body>"
    +"<!--[if gte mso 9]>"
    +"<xml>"
    +"<x:ExcelWorkbook>"
    +"<x:ExcelWorksheets>"
    +"<x:ExcelWorksheet>"
    +"<x:OWCVersion>9.0.0.2710</x:OWCVersion>"
    +"<x:Label Style='border-top:solid .5pt silver;border-left:solid .5pt silver;   order-right:solid .5pt silver;border-bottom:solid .5pt silver'>"
    +"<x:Caption>"+ title +"</x:Caption>"
    +"</x:Label>"
    +"<x:Name>Sheet1</x:Name>"
    +"<x:WorksheetOptions>"
    +"<x:Selected/>"
    +"<x:Height>7620</x:Height>"
    +"<x:Width>15240</x:Width>"
    +"<x:TopRowVisible>0</x:TopRowVisible>"
    +"<x:LeftColumnVisible>0</x:LeftColumnVisible>"
    +"<x:ProtectContents>False</x:ProtectContents>"
    +"<x:DefaultRowHeight>210</x:DefaultRowHeight>"
    +"<x:StandardWidth>2389</x:StandardWidth>"
    +"</x:WorksheetOptions>"
    +"</x:ExcelWorksheet>"
    +"</x:ExcelWorksheets>"
    +"<x:SpreadsheetAutoFit/>"
    +"<x:MaxHeight>80%</x:MaxHeight>"
    +"<x:MaxWidth>80%</x:MaxWidth>"
    +"</x:ExcelWorkbook>"
    +"</xml><![endif]-->"
    +"<table class=wcC24FAB9 x:str>"
    for (var i=0;i<ar[0].length;i++) {
    s_head+="<col class=wcC24FAB9 width=\"200\" style='mso-width-source:userset'> "
    }
    s_head+="<tr height=\"14\"><td align=\"center\" colspan=\"" + ar[0].length + "\"><font size=\"3\">" + title+ "</font></td></tr>"
    for (var i=0;i<ar.length;i++){
    s_head+="<tr height=\"14\"> "
    for(var j=0;j<ar[0].length;j++){
    s_head += "<td class=wcC24FAB9>" + ar[i][j] + "</td>"
    }
    s_head+="</tr>"
    }
    s_head+="</table></body></html>" Spreadsheet1.HTMLData=s_head;
    //alert(Spreadsheet1.HTMLData)

    showExceldiv.style.display="block";
    }
    //-->
    </SCRIPT>
    <div id="showExceldiv" style="display:none">
    <object classid="clsid:0002E510-0000-0000-C000-000000000046" id="Spreadsheet1" codebase="" width="100%" height="1400"> 
    </object>
    </div>
    </BODY>
    </HTML>
      

  2.   


    <TABLE border=1 id="srctb">
    <TR><TD rowspan=2>asdasd</TD><TD>asdf</TD><TD>asdf</TD><TD>asdf</TD></TR>
    <TR><TD>asdf</TD><TD>adf</TD><TD>asdf</TD></TR>
    <TR><TD colspan=3>dfff</TD><TD>sdf</TD></TR>
    </TABLE>
    <object classid="clsid:0002E510-0000-0000-C000-000000000046" id="Spreadsheet1"  codebase="" width="100%" height="1400">  
    </object><SCRIPT LANGUAGE="JavaScript">
    <!--
    function showExcelbyTB(tb,title){
    var s_head="<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\">"
    +"<head><style type=\"text/css\">"
    +"<!--"
    +"tr {mso-height-source:auto;}"
    +"td {white-space:nowrap;}"
    +".wcC24FAB9 {white-space:nowrap;font-family:宋体;mso-number-format:General;font-size:auto;font-weight:auto;font-style:auto;text-decoration:auto;mso-background-source:auto;mso-pattern:auto;mso-color-source:auto;text-align:general;vertical-align:bottom;border-top:none;border-left:none;border-right:none;border-bottom:none;mso-protection:locked;}"
    +".wcCF5FAB9 {white-space:nowrap;font-family:宋体;mso-number-format:General;font-size:auto;font-weight:auto;font-style:auto;text-decoration:auto;mso-background-source:auto;mso-pattern:auto;mso-color-source:auto;text-align:general;vertical-align:bottom;border-top:none;border-left:none;border-right:none;border-bottom:none;mso-protection:unlocked;}"
    +"-->"
    +"</style></head><body>"
    +"<!--[if gte mso 9]>"
    +"<xml>"
    +"<x:ExcelWorkbook>"
    +"<x:ExcelWorksheets>"
    +"<x:ExcelWorksheet>"
    +"<x:OWCVersion>9.0.0.2710</x:OWCVersion>"
    +"<x:Label Style='border-top:solid .5pt silver;border-left:solid .5pt silver;   order-right:solid .5pt silver;border-bottom:solid .5pt silver'>"
    +"<x:Caption>"+ title +"</x:Caption>"
    +"</x:Label>"
    +"<x:Name>Sheet1</x:Name>"
    +"<x:WorksheetOptions>"
    +"<x:Selected/>"
    +"<x:Height>7620</x:Height>"
    +"<x:Width>15240</x:Width>"
    +"<x:TopRowVisible>0</x:TopRowVisible>"
    +"<x:LeftColumnVisible>0</x:LeftColumnVisible>"
    +"<x:ProtectContents>False</x:ProtectContents>"
    +"<x:DefaultRowHeight>210</x:DefaultRowHeight>"
    +"<x:StandardWidth>2389</x:StandardWidth>"
    +"</x:WorksheetOptions>"
    +"</x:ExcelWorksheet>"
    +"</x:ExcelWorksheets>"
    +"<x:SpreadsheetAutoFit/>"
    +"<x:MaxHeight>100%</x:MaxHeight>"
    +"<x:MaxWidth>100%</x:MaxWidth>"
    +"</x:ExcelWorkbook>"
    +"</xml><![endif]-->";
    //s_head+=eval("document.all(\""+tb+"\").outerHTML");
    var obj = eval("document.all(\""+tb+"\")");
    s_head+=obj.outerHTML;

    s_head+="</body></html>";
    return s_head;

    }
    Spreadsheet1.HTMLData=showExcelbyTB("srctb","for test");
    //-->
    </SCRIPT>