2018-04-12
출처: https://www.fun25.co.kr/blog/php-excel-reader-phpexcel-example/?category=004

PHPEXCEL의 수많은 기능중에 간단히 엑셀을 읽어주는 기능만 하는 소스이다.
아래는 필자가 살짝 고친 소스이다.
require_once dirname(__FILE__) . '/PHPExcel/IOFactory.php';

$tmp1 = array();
$filepath = $row['excel_file'];
if(!file_exists($filepath)) die(json_encode($tmp1));

$filetype = PHPExcel_IOFactory::identify($filepath);
$reader = PHPExcel_IOFactory::createReader($filetype);
$php_excel = $reader->load($filepath);

$sheet = $php_excel->getSheet(0);           // 첫번째 시트
$maxRow = $sheet->getHighestRow();          // 마지막 라인
$maxColumn = $sheet->getHighestColumn();    // 마지막 칼럼

$target = "A"."1".":"."$maxColumn"."$maxRow";
$lines = $sheet->rangeToArray($target, NULL, TRUE, FALSE);

foreach ($lines as $tk => $tv) {
	$tmp2 = array();
	foreach( $tv as $tk2=>$tv2){
		$tmp2[$tk2] = $tv2;
	}
	$tmp1 []= $tmp2;
}

echo json_encode($tmp1);