How to Convert Excel Sheet into PHP Array using PHPExcel
PHPExcel has several classes inside it to handle different objects. Inorder to handle a worksheet we need to use PHPExcel_Worksheet. This class provide a funtion called toArray() which can be used to convert an Excel worksheet into a php array.
Syntax
toArray($nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false)
Example
require_once 'PHPExcel/IOFactory.php';
$file_info = pathinfo($_FILES["result_file"]["name"]);
$file_directory = "assets/upload/";
$new_file_name = date("dmY").time().$_FILES["result_file"]["name"];
if(move_uploaded_file($_FILES["result_file"]["tmp_name"], $file_directory . $new_file_name))
{
$file_type = PHPExcel_IOFactory::identify($file_directory . $new_file_name);
$objReader = PHPExcel_IOFactory::createReader($file_type);
$objPHPExcel = $objReader->load($file_directory . $new_file_name);
$sheet_data = $objPHPExcel->getActiveSheet()->toArray(null, True, True, True);
print_r($sheet_data);
}
Leave a Reply