Welcome Guest, Not a member yet? Register   Sign In
Reading large Excel files
#10

You dont need to create a Library. 

Once you've put in in third party, you can easily do this 

PHP Code:
?php
/**
* Excel dengan CI & Spout
*
*/
//load Spout Library
require_once APPPATH.'/third_party/spout/src/Spout/Autoloader/autoload.php';

//lets Use the Spout Namespaces
use Box\Spout\Reader\ReaderFactory;
use 
Box\Spout\Common\Type;

class 
Export extends CI_Controller {

 
     public function readExcelFile() {

 
         try {
 
          
               
//Lokasi file excel       
 
              $file_path "C:\file_excel.xlsx"                    
               $reader 
ReaderFactory::create(Type::XLSX); //set Type file xlsx
 
              $reader->open($file_path); //open the file          
 
          
                $i 
0
 
                                  
                
/**                  
                * Sheets Iterator. Kali aja multiple sheets                  
                **/ 
          
                foreach 
($reader->getSheetIterator() as $sheet) {

 
                   //Rows iterator                
 
                   foreach ($sheet->getRowIterator() as $row) {

 
                       print_r($row); 
 
                 
                        
++$i;
 
                   }
 
               }

 
               echo "Total Rows : " $i             
                $reader
->close();
 
                           

               
echo "Peak memory:", (memory_get_peak_usage(true) / 1024 1024), " MB";

 
     } catch (Exception $e) {

 
             echo $e->getMessage();
 
             exit  
      
}

 
 }//end of function 


}//end of class


this will output 

Array
(
 
   [0] => SPP-16755
    
[1] => 42198
    
[2] => Mester SERVER
    
[3] => Rp.9000
    
[4] => Banjarmasin
)
....
....

Total Rows 6171 
Peak memory usage
2 MB

Read Big Excel File Using PHP Spout Library 
Reply


Messages In This Thread
Reading large Excel files - by Wouter60 - 08-14-2017, 12:01 PM
RE: Reading large Excel files - by Paradinight - 08-14-2017, 12:15 PM
RE: Reading large Excel files - by InsiteFX - 08-14-2017, 12:23 PM
RE: Reading large Excel files - by Wouter60 - 08-14-2017, 01:04 PM
RE: Reading large Excel files - by dsivic - 08-14-2017, 01:23 PM
RE: Reading large Excel files - by Wouter60 - 08-14-2017, 02:03 PM
RE: Reading large Excel files - by Paradinight - 08-14-2017, 11:51 PM
RE: Reading large Excel files - by Wouter60 - 08-15-2017, 11:27 AM
RE: Reading large Excel files - by projack89 - 08-15-2017, 02:32 AM
RE: Reading large Excel files - by tksains - 08-23-2017, 08:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB