如何在单个zip文件中保存多个excel文件

时间:2015-01-12 12:17:14

标签: php codeigniter phpexcel

我的excel文件代码如下......

$dte=date('d-m-Y',strtotime($dt));
$fname='Logsheet_'.$dte.'_Zone_' .$zone_id.'.xls';
$filename='Backup.xls'; //save our workbook as this file name
header('Content-Type: application/vnd.ms-excel'); //mime type
header('Content-Disposition: attachment;filename="'.$fname.'"'); //tell browser what's the file name
header('Cache-Control: max-age=0'); //no cache
//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
//if you want to save it as .XLSX Excel 2007 format
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
//force user to download the Excel file without writing it to server's HD
$objWriter->save('php://output');

然后我想知道,我怎样才能将这个代码更改为单个zip文件作为输出,因为我可以将多个excel文件放入。

1 个答案:

答案 0 :(得分:1)

确定。我认为你不是专业的Google员工而且我以前做过这个,但我不会给你整个解决方案。在PHP中有一个名为ZipArchive的类。它在服务器上创建zip文件。它非常易于使用。网址为here。基本工作流程是:

  • 将excel文件保存到服务器

  • 将这些文件放入数组

  • 通过ZipArchive
  • 创建一个空拉链
  • 预先处理文件数组并将其添加到zip文件
  • 保存zip文件
  • 将zip文件发送到标题。

ZipArchive已有详细记录,我相信您会在那里找到解决方案。

度过美好的一天!