php导出带加密的excel

最近需要用yii2做一个导出excel带密码设置的功能,找了好多都没有达到目的,后来终于在git找到了一个,不过得php版本7.4以上

https://github.com/nick322/secure-spreadsheet

$objWriter = new Xlsx($objPHPExcel);

        $file_path = $title . '.xlsx';
        $objWriter->save($file_path);//保存到本地

        //设置excel文件打开密码
        $xlsx_encrypt = new Encrypt();
        $xlsx_encrypt->input($file_path)
            ->password($data['password'])
            ->output($file_path);

        header('Content-Type: application/octet-stream');
        header('Content-Transfer-Encoding: Binary');
        header("Content-disposition: attachment; filename=\"" . basename($file_path) . "\"");
        readfile($file_path);

        @unlink($file_path);

 

posted on 2023-07-19 15:32  xuxxnb  阅读(253)  评论(0编辑  收藏  举报

导航