<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 一,安裝phpshpreadsheet 1,composer安裝 ~~~ liuhongdi@lhdpc:~$ cd /data/php/admapi/ liuhongdi@lhdpc:/data/php/admapi$ composer require phpoffice/phpspreadsheet ~~~ 2,查看版本: [![復制代碼](https://common.cnblogs.com/images/copycode.gif)](javascript:void(0); "復制代碼") ~~~ liuhongdi@lhdpc:/data/php/admapi$ composer show phpoffice/phpspreadsheet name : phpoffice/phpspreadsheet descrip. : PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine keywords : OpenXML, excel, gnumeric, ods, php, spreadsheet, xls, xlsx versions : * 1.21.0 type : library license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText homepage : https://github.com/PHPOffice/PhpSpreadsheet source : [git] https://github.com/PHPOffice/PhpSpreadsheet.git 1a359d2ccbb89c05f5dffb32711a95f4afc67964 dist : [zip] https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/1a359d2ccbb89c05f5dffb32711a95f4afc67964 1a359d2ccbb89c05f5dffb32711a95f4afc67964 path : /data/php/admapi/vendor/phpoffice/phpspreadsheet names : phpoffice/phpspreadsheet … ~~~ [![復制代碼](https://common.cnblogs.com/images/copycode.gif)](javascript:void(0); "復制代碼") ? ? ? ? ?對應的源碼可以訪問這里獲取:?[https://github.com/liuhongdi/ ](https://github.com/liuhongdi/)? ? ? ? ?或:?[https://gitee.com/liuhongdi](https://gitee.com/liuhongdi) ## 二,編寫php代碼 1,類庫 lib/util/excel.php [![復制代碼](https://common.cnblogs.com/images/copycode.gif)](javascript:void(0); "復制代碼") ~~~ <?php namespace app\lib\util; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; class excel { /* * 把導出為excel到瀏覽器并下載 * $title:標題 * $headArr: 表頭 * $data: 數據 * $fileName:文件名 * */ function excelExport($title="",$headArr = [], $data = [],$fileName = '') { $fileName .= "_" . date("Y_m_d", time()) . ".xls"; $spreadsheet = new Spreadsheet(); $objPHPExcel = $spreadsheet->getActiveSheet(); $objPHPExcel->setTitle($title); $objPHPExcel->setCellValueByColumnAndRow(1, 1, $title); // 設置表頭 $key = ord("A"); foreach ($headArr as $v) { $colum = chr($key); $objPHPExcel->setCellValue($colum . '1', $v); $key += 1; } $column = 2; foreach ($data as $key => $rows) { // 行寫入 $span = ord("A"); foreach ($rows as $keyName => $value) { // 列寫入 $objPHPExcel->setCellValue(chr($span) . $column, $value); $span++; } $column++; } header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="' . $fileName . '.xlsx"'); header('Cache-Control: max-age=0'); $writer = new Xlsx($spreadsheet); $writer->save('php://output'); //刪除臨時的sheet $spreadsheet->disconnectWorksheets(); unset($spreadsheet); exit; } } ~~~ [![復制代碼](https://common.cnblogs.com/images/copycode.gif)](javascript:void(0); "復制代碼") 2,在controller中調用: controller/Article.php [![復制代碼](https://common.cnblogs.com/images/copycode.gif)](javascript:void(0); "復制代碼") ~~~ use app\lib\util\excel; class Article extends BaseController { //導出為excel文件 public function excel() { $fileName="2022年員工名單"; $title="2022年員工名單"; $headArr = ['id', 'name', 'sex']; $data = [ [1,'老劉','男'], [2,'老馬','女'], [3,'小劉','男'], ]; $excelObj = new excel(); $excelObj->excelExport($title, $headArr, $data,$fileName); } } ~~~ [![復制代碼](https://common.cnblogs.com/images/copycode.gif)](javascript:void(0); "復制代碼") ## 三,測試效果 1,訪問: ~~~ http://192.168.219.6:8000/article/excel ~~~ 2,查看導出的文件: ![](https://img.kancloud.cn/78/02/78026024693da3e441aa8d51136a5008_1108x758.png) ## 四,查看php和thinkphp的版本:? php: ~~~ liuhongdi@lhdpc:/data/php/admapi$ php --version PHP 8.1.1 (cli) (built: Dec 20 2021 16:12:16) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.1, Copyright (c) Zend Technologies with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies? ~~~ thinkphp: ~~~ liuhongdi@lhdpc:/var/www/html$ cd /data/php/admapi/ liuhongdi@lhdpc:/data/php/admapi$ php think version v6.0.10LTS ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看