phpExcel 官方停止更新,不支持php7.4以上版本,改用 phpspreadsheet

hykeda3年前ThinkPHP3277
composer require phpoffice/phpspreadsheet

安装后:

按需要引入文件

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use \PhpOffice\PhpSpreadsheet\IOFactory;

		//读取模板
 		$spreadsheet  = IOFactory::load(public_path('excel/exportOrder.xlsx'));
 		// 读取第一个工作表
        $excelSheet = $spreadsheet->getSheet(0);
        $activerow = 2;
        //插入所有需要的行数
        $excelSheet-> insertNewRowBefore(3, sizeof($customer));
          //移除行数
        $excelSheet->removeRow(2, 1);
        foreach ($customer as $k => $v) {
           $excelSheet->setCellValue('A'.$activerow, $v->email);
         
           $activerow++;
      	}
        $filename = '客户订单汇总'.$time.".xlsx";
        //直接输出到浏览器
        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header('Content-Disposition: attachment;filename="'.$filename.'"');
        header('Cache-Control: max-age=0');
        $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet , 'Xlsx');
        $writer->save('php://output');


标签: excel

相关文章

thinkphp6 使用中的注意点

thinkphp6 使用中的注意点

1、TP6中采用多应用模式需要安装  composer require topthink/think-multi-app如果需要使用view,还必须安装模板引擎...

Thinkphp5 创建模块

一、创建三个模块 Common(公共模块),Index(前台模块),Admin(后台模块)。 index.php实际配置 <?php // 定义应用目录 define('APP_...

最新阿里云OSS文件上传部署

1、前往阿里云github下载SDK包:https://github.com/aliyun/aliyun-oss-php-sdk/releases。 这里介绍源码部署:Source code下载下来...

composer安装插件包的时候提示PHP 版本不匹配

因为安装的 PHP 是 8.0 ,不匹配 composer.json 要求的版本,所以使用 composer 进行安装时会报错。在安装命令后加上 --ignore-pla...

关于thinkphp6 where以数组形式查询,其中有or,and的处理

最近在写tp6的查询语句时,如果查询条件以数组形式传入,比如:$where[] = ['id','=',$id]; $where[] =...

thinkphp5 微信token验证不通过

刚想接入下微信公众平台,用了最新的tp5,之前用的是tp3.2.3,发现配置好文件后,微信后台一直提示token验证失败。 但是直接在入口文件写echo $_GET["echostr"];就会提...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。