我正在通过 phpexcel 将一些数据写入 excel 工作表。生成的文件包含 500 行和大约 35 列。运行脚本需要两分钟+,有什么方法可以优化它吗?谢谢你
下面是我的脚本
require_once 'lib_phpexcel/PHPExcel.php';
ini_set('memory_limit', "512M");
ini_set('max_execution_time', 800);
$objPHPExcel = new PHPExcel();
// proprietes documents
$objPHPExcel->getProperties()->setCreator(utf8_encode("COCPIT"))
->setTitle(utf8_encode("COCPIT - Cohérence"))
->setSubject(utf8_encode("COCPIT - Cohérence"))
->setDescription(utf8_encode("COCPIT - Cohérence"));
$objPHPExcel->setActiveSheetIndex(0);
$sheet = $objPHPExcel->getActiveSheet();
$index_ligne = 4;
$res = mysql_query("SELECT * FROM $database.TEMP_CatalogueSI_RPS LIMIT 2, 999999999999") or die (mysql_error());
while($row = mysql_fetch_row($res)){
$index_colonne = 0;
foreach($row as $value){
$range_colonne = getColonne(++$index_colonne);
$id_cell = $range_colonne . $index_ligne;
$sheet->setCellValue($id_cell, utf8_encode($value));
$sheet->getStyle($id_cell)->applyFromArray($styleCelluleColonneInfos);
// Pour les 8 premières colonnes => on est sur des colonnes 'fixes'
if($index_colonne > 8){
if(strcasecmp($value, "X") === 0){
$sheet->getStyle($id_cell)->getFill()->getStartColor()->setRGB('CCFFCC');
}
else{
$sheet->getStyle($id_cell)->getFill()->getStartColor()->setRGB('C0C0C0');
}
}
}
$index_ligne++;
}
$file = "db/$database/TEMP_CatalogueSI_RPS.xls";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save($file);