简体   繁体   English

PHPSpreadSheet Writer Xlx 在 PHP 7.0 版中不起作用

[英]PHPSpreadSheet Writer Xlx doesn't work in PHP version 7.0

So I made this program to export data from database into excel format with PHP language and library called PHPSpreadsheet.所以我制作了这个程序,用 PHP 语言和名为 PHPSpreadsheet 的库将数据库中的数据导出为 excel 格式。 In localhost the program works fine.在 localhost 中,程序运行良好。 But in online server the program is not working.但是在在线服务器中,程序不起作用。 Does this have issue with PHP version, cause in my localhost, it's PHP 7.2 but in online server is 7.0.这是否与 PHP 版本有关,因为在我的本地主机中,它是 PHP 7.2,但在在线服务器中是 7.0。

Is there any other library for export excel with PHP version 7.0? PHP 7.0 版是否还有其他用于导出 excel 的库? I have tried PHPExcel but they said its deprecated for php 7.x我试过 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)
?>

I have tried to display the error and the export worked but when I opened the excel it shows error.我试图显示错误并且导出成功,但是当我打开 excel 时它显示错误。 Here is the error:这是错误:

Warning : ZipArchive::close(): Failure to create temporary file: No such file or directory in /home/admin/web/domain.com/public_html/admin/data/daftar_diklat/excel/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php on line 409警告:ZipArchive::close():创建临时文件失败: /home/admin/web/domain.com/public_html/admin/data/daftar_diklat/excel/vendor/phpoffice/phpspreadsheet/src/ 中没有这样的文件或目录第409行的PhpSpreadsheet/Writer/Xlsx.php

Fatal error : Uncaught PhpOffice\\PhpSpreadsheet\\Writer\\Exception: Could not close zip file php://output.致命错误:未捕获的 PhpOffice\\PhpSpreadsheet\\Writer\\Exception:无法关闭 zip 文件 php://output。 in /home/admin/web/domain.com/public_html/admin/data/daftar_diklat/excel/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php:410 Stack trace: #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 {main} thrown in /home/admin/web/domain.com/public_html/admin/data/daftar_diklat/excel/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php on line 410在 /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 {main} 扔在/home /admin/web/domain.com/public_html/admin/data/daftar_diklat/excel/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php410

And this is my server:这是我的服务器:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM