header('Content-type: text/html; charset=utf-8'); //设置页面编码
require_once 'phpexcel.class.php'; //引入文件
require_once 'PHPExcel/IOFactory.php'; //引入文件
require_once 'PHPExcel/Reader/Excel2007.php'; //引入文件
$uploadfile = $_FILES['select_file']['tmp_name']; //获取上传文件
$auid = $_SESSION['auid'];
$date = date('Ymd');
$rand = rand(1, 9999);
$_month = str_replace('-', '', $date);
$file_name = str_pad($auid, 4, 0, STR_PAD_LEFT).$date.str_pad($rand, 4, 0, STR_PAD_LEFT).'.xlsx';
$path_file = '../data/upload/file/'.$file_name; //上传文件目录指定
move_uploaded_file($uploadfile, $path_file); //文件上传
$inputFileType = PHPExcel_IOFactory: :identify($path_file);
$objReader = PHPExcel_IOFactory: :createReader($inputFileType);
$objReader - >setReadDataOnly(true); //只需要添加这个方法实现表格数据格式转换
$objPHPExcel = $objReader - >load($path_file);
$sheet_read_arr = array();
$sheet_read_arr["表1"] = array("B", "C");
$sheet_read_arr["表2"] = array("B", "C");
$sheet_read_arr["表3"] = array("B", "C");
$list_aray = array();
foreach($sheet_read_arr as $key = >$val) {
$currentSheet = $objPHPExcel - >getSheetByName($key);
$row_num = $currentSheet - >getHighestRow();
for ($i = 6; $i <= $row_num; $i++) {
$cell_values = array();
foreach($val as $cell_val) {
$address = $cell_val.$i; // 单元格坐标
$cell_values[] = $currentSheet - >getCell($address) - >getFormattedValue();
}
$list_aray[] = $cell_values;
}
}
来源: http://www.cnblogs.com/sztx/p/7405807.html