:::

7-5-1 產生 Excel 檔

您沒有觀看影片的權限

您沒有觀看影片的權限

請先登入,登入後,確認您的權限後,即可觀看影片。

  1. PHPExcel官網(舊):https://github.com/PHPOffice/PHPExcel
  2. PHPExcel API手冊:http://oweb1.osakac.ac.jp/labs/koeda/tmp/phpexcel/Documentation/API/elementindex.html
  3. PhpSpreadsheet官網(新):https://github.com/PHPOffice/PhpSpreadsheet
  4. 舊專案已停止維護,但新專案PHP需5.6以上,為取得較好相容性,目前仍以舊專案為主
  5. 可讀取、產生Excel 97~2007的檔案,甚至可輸出PDF、CSV、HTML檔。
  6. 安裝需求:PHP 5.2.0 以上、需開啟 php_zipphp_xmlphp_gd2 函式庫。
  7. 產生 Excel 的基本架構:
    <?php
    use XoopsModules\Tadtools\Utility;
    /*-----------引入檔案區--------------*/
    require_once __DIR__ . '/header.php';
    
    require_once XOOPS_ROOT_PATH . '/modules/tadtools/vendor/phpoffice/phpexcel/Classes/PHPExcel.php'; //引入 PHPExcel 物件庫
    require_once XOOPS_ROOT_PATH . '/modules/tadtools/vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php'; //引入PHPExcel_IOFactory 物件庫
    $objPHPExcel = new PHPExcel(); //實體化Excel
    //----------內容-----------//
    
    
    $title = (_CHARSET === 'UTF-8') ? iconv('UTF-8', 'Big5', $title) : $title;
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header("Content-Disposition: attachment;filename={$title}.xlsx");
    header('Cache-Control: max-age=0');
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    
    // 避免excel下載錯誤訊息
    for ($i = 0; $i < ob_get_level(); $i++) {
        ob_end_flush();
    }
    ob_implicit_flush(1);
    ob_clean();
    $objWriter->setPreCalculateFormulas(false);
    $objWriter->save('php://output');
    exit;

     

  8. 利用上述語法建立 excel.php,一樣用它來產生報名資料
  9. templates\op_tad_signup_actions_show.tpl 中加入下載按鈕
    <a href="<{$xoops_url}>/modules/tad_signup/excel.php?id=<{$id}>&type=signup" class="btn btn-success"><i class="fa fa-file-excel-o" aria-hidden="true"></i> 匯出Excel名單</a>

     

link to https://github.com/tadlearn/tad_signup/commit/c77ee48e6f50d96482e75f169f9cdcde3a0615ea \


:::

搜尋

QR Code 區塊

https%3A%2F%2Fwww.tad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D48%26tbdsn%3D1752

書籍目錄

展開 | 闔起

線上使用者

26人線上 (8人在瀏覽線上書籍)

會員: 0

訪客: 26

更多…