/**
  * Read and extract records from file
  *
  * @param $file
  * @return array
  */
 protected function extractRecords($file)
 {
     return $this->excel->load($file)->all()->toArray();
 }
예제 #2
0
 /**
  * Start the Batach
  * @param  Excel   $excel
  * @param  array   $files
  * @param  Closure $callback
  * @return Excel
  */
 public function start(Excel $excel, $files, Closure $callback)
 {
     // Set excel object
     $this->excel = $excel;
     // Set files
     $this->_setFiles($files);
     // Do the callback
     if ($callback instanceof Closure) {
         foreach ($this->getFiles() as $file) {
             // Load the file
             $excel = $this->excel->load($file);
             // Do a callback with the loaded file
             call_user_func($callback, $excel, $file);
         }
     }
     // Return our excel object
     return $this->excel;
 }
예제 #3
0
 /**
  * Load an existing file
  *
  * @param string $file The file we want to load
  * @param callback|null $callback
  * @param string|null $encoding
  * @param bool $noBasePath
  * @return \Maatwebsite\Excel\LaravelExcelReader 
  * @static 
  */
 public static function load($file, $callback = null, $encoding = null, $noBasePath = false)
 {
     return \Maatwebsite\Excel\Excel::load($file, $callback, $encoding, $noBasePath);
 }
예제 #4
0
 public function import(Excel $excel, ImportRequest $request)
 {
     $file = $request->file('excel');
     //Input::file('excel');
     //dd($file);
     if (!$file) {
         Flash('Seleccione un archivo!!');
         return Redirect()->route('clients');
     }
     $excel->load($file, function ($reader) {
         foreach ($reader->get() as $client) {
             // para evitar en los campos que no se permiten null poner en blanco
             $data = array_map(function ($v) {
                 return is_null($v) ? "" : $v;
             }, $client->toArray());
             /* $data = [
                    'name' => $client->title,
                    'author' =>$client->author,
                    'year' =>$client->publication_year
                ];*/
             $this->clientRepo->store($data);
         }
     });
     //return Book::all();
     Flash('Imported !!');
     return Redirect()->route('clients');
 }
예제 #5
0
 public function parse(Request $request)
 {
     $file = $request->file('file');
     return $this->excel->load($file)->get();
 }
예제 #6
0
 /**
  * Load an existing file
  * 
  * @param  string $file The file we want to load
  *
  * @param callback|null $callback @param  string|null $encoding
  *  @return LaravelExcelReader
  * @static 
  */
 public static function load($file, $callback = null, $encoding = null)
 {
     return \Maatwebsite\Excel\Excel::load($file, $callback, $encoding);
 }