PHPExcel导入
PHPExcel
是用来操作Office Excel 文档的一个PHP类库,可以使用它来读取、写入不同格式的电子表格
Github:https://github.com/PHPOffice/PHPExcel
文件数据
php
<?php
require_once "PHPExcel-1.8/Classes/PHPExcel.php";
$filename='product.xls';//要导入的文件
$objReader = new PHPExcel_Reader_Excel2007();
$objPHPExcel = $objReader->load($filename);
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow(); // 总行数
$highestColumn = $sheet->getHighestColumn(); // 总列数
//循环读取每个单元格的数据
$data = array();
for ($row = 2; $row <= $highestRow; $row++) //行号从1开始
{
$tmpRow = array();
for ($column = 'A'; $column <= $highestColumn; $column++) //列数是以A列开始
{
$tmpRow[] = $sheet->getCell($column.$row)->getValue();
}
$data[] = $tmpRow;
}
echo '<pre>';
print_r($data);
/**
输出结果:
Array
(
[0] => Array
(
[0] => aaa
[1] => 10
)
[1] => Array
(
[0] => bbb
[1] => 2
)
[2] => Array
(
[0] => ccc
[1] => 3
)
)
*/