跳到主要內容

發表文章

目前顯示的是 4月, 2023的文章

PHP + CI4 的 PhpSpreadsheet 的處理

0、需要用到的 Library use \PhpOffice\PhpSpreadsheet\Spreadsheet; use \PhpOffice\PhpSpreadsheet\Writer\Xlsx; use \PhpOffice\PhpSpreadsheet\Reader\Xlsx; use \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; 參考資料: Welcome to PhpSpreadsheet's documentation - PhpSpreadsheet Documentation  1、上傳 excel 檔案並讀取內容 //處理上傳 try {             $thefile = $this->request->getFile('theuploadfile'); } catch (\Exception $e) { echo $e; exit; } try { $path = $thefile->store(); } catch (\Exception $e) { echo $e; exit; } //確認檔案格式並讀取內容 $filename = WRITEPATH . 'uploads/' . $path; $fileext = ucfirst($thefile->getClientExtension()); if (in_array($fileext, array('Xls', 'Xlsx'))) { $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($fileext); $spreadsheet = $reader->load($filename); $sheet = $spreadsheet->getSheet(0); $data = $sheet->getCell('A1')->getValue(); } 2、產生 Excel 檔案 / /生成試算表並設定格式 $spreadsheet = new Spreadsheet(); $spreadsh

幾個 Linux command

搜尋 n 天前有修改的檔案 find -mtime -n 刪除 n 天前建立的檔案 find -mtime +n -exec rm {} \; 以檔名規則搜尋檔案並刪除 find . -name "abc*" -delete 同步排除某些資料夾或檔案 rsync -r -q --exclude "dir*" --exclude "file*.txt" [source] [distination]