Excel 表匯入資料

chenBJ發表於2019-06-01
\DB::table($tableName)->truncate(); //先清空表
        if($tableName == "game_challenges") {
            \DB::table('game_challenge_commands')->truncate(); //先清空表
        }
        $filePath = '/home/share/update_db/'.$tableName.'.xlsx';
        Excel::selectSheets('Sheet1')->load($filePath, function($reader) use($tableName,$options) {
            $time = time();
            $reader = $reader->getSheet(0);//獲取excel的第1張表
            $results = $reader->toArray();//獲取表中的資料

            array_shift($results);
            foreach ($results as $k => $v) {
                if($v[0] === null) {
                    unset($results[$k]);
                }
            }
            $time = time();
            $arr = [];

laravel5,5 安裝擴充套件包"maatwebsite/excel": "~2.1.0"

相關文章