php读取excel文件的简单实例
程序员文章站
2023-11-14 20:46:58
复制代码 代码如下: $this->loadexcel();//半酣phpexcel文件 &nb...
复制代码 代码如下:
$this->loadexcel();//半酣phpexcel文件
$_readexcel = new phpexcel_reader_excel2007();
if(!$_readexcel->canread('link.xls')){
$_readexcel = new phpexcel_reader_excel5();
}
$_phpexcel = $_readexcel->load('link.xls');
$sheetcount = $_phpexcel->getsheetcount();
$newexcel = array();
$exceldata = array();
for($s = 0;$s<$sheetcount;$s++) {
$currentsheet = $_phpexcel->getsheet($s);
$allcolumn = $currentsheet->gethighestcolumn();
$allrow = $currentsheet->gethighestrow();
for($r = 1;$r<=$allrow;$r++){
for($currentcolumn='a';$currentcolumn<=$allcolumn;$currentcolumn++){
$address = $currentcolumn.$r;
$newexcel[] = $currentsheet->getcell($address)->getvalue();
}
}
}
后面就是对数组的操作了--不过要先下载好phpexcel,并包含进来