【问题标题】:compression problems excell using Maatwebsite压缩问题 Excel 使用 Maatwebsite
【发布时间】:2019-05-10 14:09:00
【问题描述】:

问题很简单,我尝试压缩文件的形式是下一个

 $zipname = 'file.zip';
 $zip = new ZipArchive;
 $zip->open($zipname, ZipArchive::CREATE);
 $zip->addFile(Excel::download(new SheetsExports($page1, $page2), $filename . '.xls'));
  $zip->close()
 echo 'Archive created!'
 header('Content-disposition: attachment; filename=files.zip');
 header('Content-type: application/zip');
 <!-- end snippet -->
 $zip->close()
 echo 'Archive created!';
 header('Content-disposition: attachment; filename=files.zip');
 header('Content-type: application/zip');

在 laravel 控制器中,我使用外部库 Maatwebsite 然后当我执行 brwoser apair 时出现下一个错误


内容损坏错误


网站http://hall.test/indiceDeRotacion?_token=2Eh6WAl0W43l8ANzLz0e4GGW9reV04ESpURvEi1H&almacen=PRINCIPAL&fechaDesde=2018-05-01&fechaHasta=2019-04-30&proveedor=3000familia=&type=xls&compresion=on&email=&asunto=&submit=informe


所以我需要一个解决方案,或另一个外部库或我的代码中的正确方法

【问题讨论】:

  • “压缩”是什么意思?给定的代码会发生什么?
  • 这是一个 ZIP 文件
  • 那么,如果该代码的结果是一个 ZIP 文件,那有什么问题呢?
  • 好吧,我在尝试使用 laravel 项目中的 maatwebsite 插件获取 Excel 压缩文件时遇到问题
  • 这可能是您在此处发布它的原因 - 但这个问题究竟是什么?有没有给出任何错误信息?运行代码时会发生什么?这与您期望此代码执行的操作有何不同?

标签: php laravel laravel-5 maatwebsite-excel


【解决方案1】:

我用这段代码解决了这个问题

 $zip = new ZipArchive;
        if ($zip->open('yyyy.zip', ZipArchive::CREATE) === true) {
            $zip->addFile(Excel::download(new SheetsExports($page1, $page2),  $filename . '.xls')->getFile(),
                'xxxx.xls');
            $zip->close();
        }
        return response()->download("yyyy.zip");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-24
    • 2017-01-02
    • 1970-01-01
    • 2020-03-10
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    相关资源
    最近更新 更多