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

hykeda3年前ThinkPHP3559
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

相关文章

thinkphp5 微信token验证不通过

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

thinkphp5页面出现500服务器内部错误

    最近写项目发现页面显示正常,控制器单独输出调试都正常,数据返回了,但还是报错get请求报错500服务器内部错误。  &nbs...

thinkphp6 使用中的注意点

thinkphp6 使用中的注意点

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

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

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

thinkphp6.1中分页类调用

$list = YourModel->paginate([     'list_rows' =>&n...

thinkphp6 前置和后置中间件的区别以及特殊情况

首先官方文档是这么描述的:中间件是在请求具体的操作之前还是之后执行,完全取决于中间件的定义本身。下面是一个前置行为的中间件 (Before命名是随意的):<?php namespace&n...

发表评论    

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