$zip = new Ziparchive;
if ($zip->open ($filePath. Date (' Ymd '). '. Zip ', ziparchive::overwrite) = = = TRUE) {
$count = $this->mod->getcount ($cond);
$num = ceil ($count/5000); //Rounding 5,000-odd 1
$z = 0;
For ($j =0; $j < $num; $j + +) {
$limit = $j *5000; //5,000 per query
$query = Array (
' pri ' = ' id ',
' Fields ' = ' * ',
' cond ' = $cond,
' order_by ' = ' id ',
' limit ' = ' $limit, '
);
$result = $this->mod->getdata ($query);
if ($result) {
$i = 2;
$objPHPExcel = new Phpexcel ();
$objPHPExcel->setactivesheetindex (0);
$objPHPExcel->getproperties ()->setcreator ("Meteoric_cry")
->setlastmodifiedby ("Meteoric002")
->settitle ("Php_excel_demo1");
$objPHPExcel->getactivesheet ()->settitle ("simple{}");
$objPHPExcel->getactivesheet ()->setcellvalue ("A1", ' title ');
$objPHPExcel->getactivesheet ()->setcellvalue ("B1", ' link ');
$objPHPExcel->getactivesheet ()->setcellvalue ("C1", ' content ');
foreach ($result as $key = = $val) {
$objPHPExcel->getactivesheet ()->setcellvalue ("a{$i}", $val [' title ']);
$objPHPExcel->getactivesheet ()->setcellvalue ("b{$i}", $val [' url ']);
$objPHPExcel->getactivesheet ()->setcellvalue ("e{$i}", $val [' content '];
$i + +;
$objWriter = new phpexcel_writer_excel2007 ($objPHPExcel);
}
//write Operation
$fileName = $key. ". Xlsx "; //File name
$objWriter->save ($fileName); //Save file
$file _path = $fileName;
if (file_exists ($file _path)) {//Determine if the file exists under this path
$zip->addfile ($file _path);
}
}
}
}
$zip->close (); //Off
//Remote Download compression package
$path = $filePath. Date (' Ymd '). '. zip ';
$file = fopen ($path, "R"); //Open file
//input file tags
Header ("Content-type:application/octet-stream");
Header ("accept-ranges:bytes");
Header ("Accept-length:". FileSize ($path));
Header ("content-disposition:attachment; Filename= ". Date (' Ymd '). ". zip");
//Output file contents
Echo fread ($file, FileSize ($path));
fclose ($file); //Close file
unlink ($path); //After downloading, delete the compressed package
PHP extracts large amounts of data from MySQL library to excel compressed download