2013-04-09 66 views
4

我使用的是cakephp的xlsHelper以excel格式導出。它在所有主流瀏覽器中工作正常,並且在除「mac」操作系統之外的所有操作系統中打開文件?使用xlsHelper導出Excel文件

回答

1

願這幫助你..

<?php 
    $this->layout=""; 
    $filename=strtotime("now"); 
    header ("Expires: 0"); 
    header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT"); 
    header ("Cache-Control: no-cache, must-revalidate"); 
    header ("Pragma: no-cache"); 
    header ("Content-type: application/vnd.ms-excel"); 
    header ("Content-Disposition: attachment; filename=".$filename.".xls"); 
    header ("Content-Description: Generated Report"); 

    // echo 'Number of Rows::'."\t" . count($test)."\n"; 
    // echo "\n"; 
    echo 'Id' . "\t" . 
      'EnrollmentId' . "\t" . 
      'IDS' . "\t" . 
      'sysreq' . "\t" . 
      'sysproc' . "\t" . 
      'Request' . "\t" . 
      'Response' . "\t" . 
      'Created' . "\n"; 
    foreach($test as $val): 
      echo $val['abc']['id']. "\t" . 
       $val['xyz']['enrollment_id']. "\t" . 
       $val['bca']['IDS']. "\t" . 
       $val['mca']['_sysreq']. "\t" . 
       $val['car']['_sysproc']. "\t" . 
       $val['azx']['SYSBATCHNO']. "\t" . 
       $val['tyu']['MSGS']. "\t" . 
       $val['wer']['created']. "\n"; 
    endforeach; 

?>