Skip to content

Instantly share code, notes, and snippets.

@spacebit-official
Last active November 27, 2017 00:17
Show Gist options
  • Save spacebit-official/dd35fdcc143039027bcc671627749856 to your computer and use it in GitHub Desktop.
Save spacebit-official/dd35fdcc143039027bcc671627749856 to your computer and use it in GitHub Desktop.
PHPExcel_Excel_to_Db
<?php
function readExelFile($filepath){
require_once __DIR__ . '/../classes/PHPExcel/PHPExcel.php'; //подключаем наш фреймворк
$ar=array(); // инициализируем массив
$inputFileType = PHPExcel_IOFactory::identify($filepath); // узнаем тип файла, excel может хранить файлы в разных форматах, xls, xlsx и другие
$objReader = PHPExcel_IOFactory::createReader($inputFileType); // создаем объект для чтения файла
$objPHPExcel = $objReader->load($filepath); // загружаем данные файла в объект
$ar = $objPHPExcel->getActiveSheet()->toArray(); // выгружаем данные из объекта в массив
return $ar; //возвращаем массив
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment