PHP 获取excel表格里面的数据

1.先下载  类库

https://github.com/PHPOffice/PHPExcel

 

 

include "./Classes/PHPExcel/IOFactory.php";

$inputFileName = "./demo.xlsx";                   
date_default_timezone_set('PRC');
// 读取excel文件
try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
} catch(Exception $e) {

}

// 确定要读取的sheet,什么是sheet,看excel的右下角,真的不懂去百度吧
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();

// 获取一行的数据
for ($row = 2; $row <= $highestRow; $row++){
// Read a row of data into an array
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
//这里得到的rowData都是一行的数据,得到数据后自行处理,我们这里只打出来看看效果
echo '

';
var_dump($rowData);
echo "
";

}

你可能感兴趣的:(excel)