PHPExcel获取.xlsx文件内容

include '/home/www/PHPExcel/Classes/PHPExcel.php';
include '/home/www/PHPExcel/Classes/PHPExcel/IOFactory.php';
$obj = PHPExcel_IOFactory::load('/home/www/a.xlsx');
/*echo '<pre>';
var_dump($obj);
echo '</pre>';*/
$sheet = $obj->getSheet(0);
//行数
$hight = $sheet->getHighestRow();
//列数
$column = $sheet->getHighestColumn();
//转换列数
$column=PHPExcel_Cell::columnIndexFromString($column);
$a=PHPExcel_Cell::stringFromColumnIndex(0);
$b=$sheet->getCell($a.'1')->getValue();
//$b=PHPExcel_Cell::stringFromColumnIndex('A');
$array=[];
for($i=0; $i<$column;$i++ ){
$numberName=PHPExcel_Cell::stringFromColumnIndex($i).'1';
$keyName=$sheet->getCell($numberName)->getValue();
array_push($array, $keyName);
}
$price=[];
for ($i=2 ;$i<$hight;$i++){
for($j=0;$j<$column;$j++){
$numberName=PHPExcel_Cell::stringFromColumnIndex($j).$i;
$keyName=$sheet->getCell($numberName)->getValue();
$row[$array[$j]]=$keyName;
}
$price[]=$row;
}
echo '<pre>';
var_dump($price);
echo '</pre>';
posted @ 2017-04-18 15:25  lpd741  阅读(1299)  评论(0编辑  收藏  举报