php读取excel函数,PHP读取Excel函数Spreadsheet_Excel_Reader

山寒
2023-12-01

require (__DIR__.'/Spreadsheet_Excel_Reader.class.php');

class ExcelReader {

public static function readXLS($file){

$data = new Spreadsheet_Excel_Reader();

$data->setOutputEncoding('UTF-8'); //设置输出的编码为utf8

$ret = $data->read($file); //要读取的excel文件地址

if($ret == -1){

$array = array('ret'=>$ret);

}else{

for ($i =1 ; $i <= $data->sheets[0]['numRows']; $i++) {

for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {

$array[$i-1][$j-1] = $data->sheets[0]['cells'][$i][$j];

}

}

}

if ( $array && is_array($array) ) {

return $array;

}

return array();

}

}

?>

 类似资料: