【问题标题】:PHPSpreadSheet Writer Xlx doesn't work in PHP version 7.0PHPSpreadSheet Writer Xlx 在 PHP 7.0 版中不起作用
【发布时间】:2020-01-01 09:27:27
【问题描述】:

所以我制作了这个程序,使用 PHP 语言和名为 PHPSpreadsheet 的库将数据库中的数据导出为 excel 格式。在 localhost 中,程序运行良好。但是在在线服务器中,该程序无法正常工作。这是否与 PHP 版本有问题,因为在我的本地主机中,它是 PHP 7.2,但在在线服务器中是 7.0。

PHP 7.0 版是否还有其他用于导出 excel 的库?我试过 PHPExcel 但他们说它不推荐用于 php 7.x

<?php
  require_once("vendor/autoload.php");
  require_once('../../connection.php');
  use PhpOffice\PhpSpreadsheet\Spreadsheet;
  use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

  // other code

  // export excel
  $writer = new Xlsx($spreadsheet);
  header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  header("Content-Disposition: attachment; filename=Pusdiklat - ".$data_diklat->nama.".xls");
  $writer->save("php://output");

  // display error
  ini_set('display_errors','1');
  ini_set('display_startup_errors','1');
  error_reporting(E_ALL);
  mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT)
?>

我试图显示错误并且导出工作,但是当我打开 excel 时它显示错误。这是错误:

警告:ZipArchive::close():未能创建临时 文件:没有这样的文件或目录 /home/admin/web/domain.com/public_html/admin/data/daftar_diklat/excel/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php409

致命错误:未捕获 PhpOffice\PhpSpreadsheet\Writer\Exception: 无法关闭 zip 文件 php://输出。在 /home/admin/web/domain.com/public_html/admin/data/daftar_diklat/excel/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php:410 堆栈跟踪: #0 /home/admin/web/domain.com/public_html/admin/data/daftar_diklat/excel/export_pusdiklat.php(139): PhpOffice\PhpSpreadsheet\Writer\Xlsx->save('php://output') #1 {主要} 扔在 /home/admin/web/domain.com/public_html/admin/data/daftar_diklat/excel/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php 在线 410

这是我的服务器:

PHP 7.0.33-0ubuntu0.16.04.3 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.33-0ubuntu0.16.04.3, Copyright (c) 1999-2017, by Zend Technologies

【问题讨论】:

  • 怎么不工作了?您是否启用了错误报告?打开所有错误报告,以便您看到可能发生的任何错误。 ini_set('display_errors','1');ini_set('display_startup_errors','1');error_reporting(E_ALL);mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
  • @Dave 感谢您的回答先生。我已经更新了这个问题,也许你能帮我解决这个问题?。
  • 确保您使用的是最新版本的 PHPSpreadsheet 并考虑更新您的 PHP 版本,因为 7.0 已不受支持。如果在您说// other code 的代码区域中有任何与 PHPSpreadsheet 相关的内容,请添加。

标签: php export-to-excel temporary-files phpspreadsheet


【解决方案1】:

对 PHP 7.0 的支持在 1.9.0 版本中被删除。

【讨论】:

    猜你喜欢
    • 2019-04-09
    • 2019-10-08
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 2018-04-03
    • 1970-01-01
    相关资源
    最近更新 更多