<table id=mytable>
<tr><td><img src="img3.gif"></td><td> nanjing</td></tr>
<tr><td> university</td><td> computer </td></tr>
</table><input type="button" value="转到Excel" onClick="SaveAsMe()" ><iframe src="" name=show style="width:0;height:0"></iframe><script language="javascript">
  function SaveAsMe() {
    show.document.write(mytable.outerHTML);
    try{
       show.document.execCommand ("SaveAs",true,"mytable.xls");
    }catch(e){
       alert("您的浏览器版本太低,请升级您的浏览器!");
    }
}
</script>

解决方案 »

  1.   

    谢谢楼上的
    不过我要把图片也写到excel文件去,就是img3.gif 删掉了excel还是可以显示图片
    怎么实现
      

  2.   

    <input type=button value='toexcel' onclick="copyToExcel();">
    <script language="JavaScript">
    var idTmr="";
    function copyToExcel(){
    var excelOBJ=new ActiveXObject("Excel.Application");
    excelOBJ.WorkBooks.Add;
    excelOBJ.ActiveSheet.Pictures.Insert("http://community.csdn.net/images/CSDN_logo.GIF");
    excelOBJ.Quit();
    excelOBJ=null;
    idTmr=window.setInterval("Cleanup();",1);
    }
    function Cleanup(){
    window.clearInterval(idTmr);
    CollectGarbage();
    }
    </script>
      

  3.   

    你可以借用Excel的“录制新宏”命令得到更多的操作代码。求人不如求自己,不必求人。