Header("Content-type: application/octet-stream");
    Header("Accept-Ranges: bytes");
    Header("Content-Disposition: attachment; filename=test.xls");    $js = "abcdefghi....";  //your js code
    echo $js;

解决方案 »

  1.   

    to:lvlfforever(那一年):大哥,这些都加了啊,
      

  2.   

    to:yueliangdao0608,由于该逻辑所涉及的代码很多,下面只贴出个相同的简洁的代码。大哥,帮忙看一下。<?php
    header("Content-type: application/octet-stream");
    header("Accept-Ranges: bytes");
    header("Content-type: application/vnd.ms-excel"); 
    header("Content-Disposition: attachment;filename=预算与跟踪.xls"); 
    ?>
    <html xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns="http://www.w3.org/TR/REC-html40"><head>
    <meta http-equiv=Content-Type content="text/html; charset=GB2312">
    <meta name=ProgId content=Excel.Sheet>
    <meta name=Generator content="Microsoft Excel 9">
    <link rel=File-List href="./Book1.xls.files/filelist.xml">
    <link rel=Edit-Time-Data href="./Book1.xls.files/editdata.mso">
    <link rel=OLE-Object-Data href="./Book1.xls.files/oledata.mso">
    <!--[if gte mso 9]><xml>
     <o:DocumentProperties>
      <o:Author>server</o:Author>
      <o:LastAuthor>server</o:LastAuthor>
      <o:Created>2005-04-06T08:48:22Z</o:Created>
      <o:LastSaved>2005-04-06T08:49:46Z</o:LastSaved>
      <o:Version>9.2812</o:Version>
     </o:DocumentProperties>
     <o:OfficeDocumentSettings>
      <o:DownloadComponents/>
      <o:LocationOfComponents HRef="file:D:\software\Soft\Office_Setup\msowc.cab"/>
     </o:OfficeDocumentSettings>
    </xml><![endif]-->
    <style>
    </style>
    <!--[if gte mso 9]><xml>
     <x:ExcelWorkbook>
      <x:ExcelWorksheets>
       <x:ExcelWorksheet>
        <x:Name>Sheet1</x:Name>
        <x:WorksheetOptions>
         <x:DefaultRowHeight>285</x:DefaultRowHeight>
         <x:Selected/>
         <x:Panes>
          <x:Pane>
           <x:Number>3</x:Number>
           <x:ActiveRow>1</x:ActiveRow>
          </x:Pane>
         </x:Panes>
         <x:ProtectContents>False</x:ProtectContents>
         <x:ProtectObjects>False</x:ProtectObjects>
         <x:ProtectScenarios>False</x:ProtectScenarios>
        </x:WorksheetOptions>
       </x:ExcelWorksheet>
       <x:ExcelWorksheet>
        <x:Name>Sheet2</x:Name>
        <x:WorksheetOptions>
         <x:DefaultRowHeight>285</x:DefaultRowHeight>
         <x:ProtectContents>False</x:ProtectContents>
         <x:ProtectObjects>False</x:ProtectObjects>
         <x:ProtectScenarios>False</x:ProtectScenarios>
        </x:WorksheetOptions>
       </x:ExcelWorksheet>
       <x:ExcelWorksheet>
        <x:Name>Sheet3</x:Name>
        <x:WorksheetOptions>
         <x:DefaultRowHeight>285</x:DefaultRowHeight>
         <x:ProtectContents>False</x:ProtectContents>
         <x:ProtectObjects>False</x:ProtectObjects>
         <x:ProtectScenarios>False</x:ProtectScenarios>
        </x:WorksheetOptions>
       </x:ExcelWorksheet>
      </x:ExcelWorksheets>
      <x:WindowHeight>8610</x:WindowHeight>
      <x:WindowWidth>14460</x:WindowWidth>
      <x:WindowTopX>720</x:WindowTopX>
      <x:WindowTopY>420</x:WindowTopY>
      <x:ProtectStructure>False</x:ProtectStructure>
      <x:ProtectWindows>False</x:ProtectWindows>
     </x:ExcelWorkbook>
    </xml><![endif]-->
    </head><body link=blue vlink=purple><table>
    <tr style="background-color:#FF0000">
    <td><span id="ss"></span></td>
    </tr>
    </table><script language="javascript">
    ss.innerHTML = "aa";
    </script> <![if supportMisalignedColumns]>
     <tr height=0 style='display:none'>
      <td width=72 style='width:54pt'></td>
     </tr>
     <![endif]></body></html>
      

  3.   

    我的程序到这一步的时候有错:
    $excel = new COM("Excel.sheet") or Die ("Did not instantiate Excel");// 建立EXCEL的COM对象错误信息:
    Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `Excel.sheet': 拒绝访问。 ' in E:\iis\libraire\excel\excel.php:40 Stack trace: #0 E:\iis\libraire\excel\excel.php(40): com->com('Excel.sheet') #1 E:\iis\libraire\excel\testclass.php(28): Excel->excel() #2 {main} thrown in E:\iis\libraire\excel\excel.php on line 40
    我用的IIS(6.0)+windows 2003 server
    我的QQ:531515035
    email :[email protected]
    谢谢指点