简体   繁体   中英

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. In localhost the program works fine. 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.

Is there any other library for export excel with PHP version 7.0? I have tried PHPExcel but they said its deprecated for 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. Here is the error:

: ZipArchive::close(): Failure to create temporary file: No such file or directory in on line :ZipArchive::close():创建临时文件失败: 没有这样的文件或目录第行的

: 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 on line

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 中被删除。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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