//导入文件
//从excel表格中读取信息
$PHPExcel= new PHPExcel();
$extension = strtolower(pathinfo($name, PATHINFO_EXTENSION));
//不同文件后缀的读取
if ($extension =='xlsx') {
$PHPReader = new PHPExcel_Reader_Excel2007();
$PHPExcel = $PHPReader ->load($path.$name);
} else if ($extension =='xls') {
$PHPReader = new PHPExcel_Reader_Excel5();
$PHPExcel = $PHPReader ->load($path.$name);
} else if ($extension=='csv') {
$PHPReader = new PHPExcel_Reader_CSV();
//默认输入字符集
$PHPReader->setInputEncoding('GBK');
//默认的分隔符
$PHPReader->setDelimiter(',');
//载入文件
$PHPExcel = $PHPReader->load($path.$name);
}
//获取工作表的数目
$sheetCount = $PHPExcel->getSheetCount();
/**循环读取多个工作表*/
for ( $i = 0; $i < $sheetCount; $i++ ) {
$currentSheet= $PHPExcel->getSheet($i);
//print_r($sheetCount);exit;
/**取得最大的列号*/
$allColumn= $currentSheet->getHighestColumn();
/**取得一共有多少行*/
$allRow= $currentSheet->getHighestRow();
/**列名转化为数字*/
$allColumnIndex = PHPExcel_Cell::columnIndexFromString($allColumn);
$excelData = array();
//取第三行的表头
$col1 = $currentSheet->getCell('A3')->getValue();
$col2 = $currentSheet->getCell('B3')->getValue();
$col3 = $currentSheet->getCell('C3')->getValue();
$col4 = $currentSheet->getCell('D3')->getValue();
$col5 = $currentSheet->getCell('E3')->getValue();
$col6 = $currentSheet->getCell('F3')->getValue();
$col7 = $currentSheet->getCell('G3')->getValue();
$col8 = $currentSheet->getCell('H3')->getValue();
$col9 = $currentSheet->getCell('I3')->getValue();
/* 从第四行开始取*/
for($currentRow =4;(is_numeric($currentRow) && $currentRow <= $allRow) ;$currentRow++)
{
/*
* 1、取值
* 2、验证格式。金额格式,身份证号不能重复,
* 3、入库
/* 从A列开始取 */
for($currentColumn =0;$currentColumn <= $allColumnIndex;$currentColumn++){
//$unitVal = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
$excelData[$currentRow][] = (string)$currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
}
if(($excelData[$currentRow][2] != "") && is_numeric($excelData[$currentRow][0]))
{
//用户信息入库
$data_rs = User::add($excelData[$currentRow],$batchid,$form_rs,$currentRow,$i);
}
}
}