2016-06-28 71 views
0

我正在從事php excel導出。在這裏,我正面臨一些問題,比如有大量的數據將近8000條記錄。數據完美地放置在單元中。我的問題是獲取記錄之前csv被下載

在3000條記錄本身csv被下載。我怎樣才能解決這個問題 ?

有沒有更多的3000到8000我該怎麼做?

示例代碼

<?php 
    // Connection 

       $tamdsreport_billing_qry = db_query($_SESSION['tamdsreport_billing_qry']); 
           while($result_tamdsreport_billing_qry = db_fetch_array($tamdsreport_billing_qry)){ 

            $datacenter_param = $result_tamdsreport_billing_qry['datacenter']; 
            $cid_param = $result_tamdsreport_billing_qry['cid']; 
            $rid_param = $result_tamdsreport_billing_qry['rid']; 
            $datastore_name_param = $result_tamdsreport_billing_qry['datastore_name']; 
            $cloud_type_param = $result_tamdsreport_billing_qry['cloud_type']; 
            $storage_type_param = $result_tamdsreport_billing_qry['storage_type']; 
            $avg_capacity_gb_param = $result_tamdsreport_billing_qry['avg_capacity_gb']; 
            $avg_free_space_gb_param = $result_tamdsreport_billing_qry['avg_free_space_gb']; 
            $avg_space_consumed_gb_param = $result_tamdsreport_billing_qry['avg_space_consumed_gb']; 
            $gb_used_param = $result_tamdsreport_billing_qry['gb_used']; 
            $start_date = $result_tamdsreport_billing_qry['start_date']; 
            $end_date = $result_tamdsreport_billing_qry['end_date']; 


           $html3[] = "<tr><td>$datacenter_param</td><td>$start_date</td><td>$end_date</td><td>$cid_param</td><td>$rid_param</td><td>$datastore_name_param</td><td>$cloud_type_param</td><td>$storage_type_param</td><td>$avg_capacity_gb_param</td><td>$avg_free_space_gb_param</td><td>$avg_space_consumed_gb_param</td><td>$gb_used_param</td></tr>"; 

         } 



     $html = "<table><tr><td>&nbsp;</td><tr><td><h3>Storage Usage for A0CA </h3> </td></tr><tr bgcolor='#445fea'><td>Data Center</td><td>Report Start Date</td><td>Report End Date</td><td>CID</td><td>RID</td><td>Data Store Name</td><td>Cloud Type</td><td>Storage Type</td><td>Avg capacity GB</td><td>Avg free space GB</td><td>Avg space consume GB</td><td>GB Used</td></tr>".implode("\r\n", $html3). "</table>"; 


     $fileName = 'tamdrp_billing_export_US.xls'; 

} 
header('Content-Type: application/octet-stream'); 
header('Content-Transfer-Encoding: binary'); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Pragma: public'); 
header("Content-Disposition: attachment; filename=$fileName"); 
echo $html; 
exit; 
?> 
+0

您是否確定生成了8000條記錄?我寧願將這些記錄保存到一個臨時文件中,並用'readfile($ tempfile)'標記這個頭文件。 –

回答

-1

你必須嘗試用PHPExcel。 我希望它能爲你工作。

require_once 'PHPExcel/Classes/PHPExcel.php'; 
$objPHPEx  = new PHPExcel(); 
$filename  = 'output.xlsx'; 
$objWorksheet = $objPHPEx->getActiveSheet(0); 
$objPHPEx->getActiveSheet()->getColumnDimension('A')->setWidth(14); 
$objPHPEx->getActiveSheet()->setCellValue('S1',123); 
$objWriter = PHPExcel_IOFactory::createWriter($objPHPEx, 'Excel2007'); 
$objWriter->save('products_inventory_files/' . $filename); 
相關問題