我正在开发php excel导出。在这里,我面临着一些问题,例如有大量数据,差不多有8000条记录。数据完美地放在单元格中。我的问题是什么
在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> </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 :(得分:-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);