时间:2021-07-01 10:21:17 帮助过:38人阅读
function import_excel($filePath){
$txt=array();
$PHPReader = new PHPExcel_Reader_Excel2007();
if(!$PHPReader->canRead($filePath)){
$PHPReader = new PHPExcel_Reader_Excel5();
if(!$PHPReader->canRead($filePath)){
echo 'no Excel';
return ;
}
}
//建立excel对象,此时你即可以通过excel对象读取文件,也可以通过它写入文件
$PHPExcel = $PHPReader->load($filePath);
/**读取excel文件中的第一个工作表*/
$currentSheet = $PHPExcel->getSheet(0);
/**取得最大的列号*/
$allColumn = $currentSheet->getHighestColumn();
/**取得一共有多少行*/
$allRow = $currentSheet->getHighestRow();
echo "allcolumn:".$allColumn."
";
echo "allRow:".$allRow."
";
//循环读取每个单元格的内容。注意行从1开始,列从A开始
for($rowIndex=1;$rowIndex<=$allRow;$rowIndex++){
for($colIndex='A';$colIndex<=$allColumn;$colIndex++){
echo $colIndex.",";
$addr = $colIndex.$rowIndex;
$cell = $currentSheet->getCell($addr)->getValue();
$txt[$rowIndex][]=$cell;
echo $cell,",";
}
echo "
";
}
return $txt;
}
for($i='A'; $i!='AA'; $i++) echo $i;ABCDEFGHIJKLMNOPQRSTUVWXYZ