关于php读取excl的一些问题

2025-03-06 21:48:46
推荐回答(1个)
回答1:

include_once('PHPExcel.class.php');    //加载phpexcel类
header("Content-type: text/html; charset=utf-8");  //设置文字编码为utf8
//read excel file;
$PHPExcel = new PHPExcel();    //实例化phpexcel类
$PHPReader = new PHPExcel_Reader_Excel5();  //实例化文件类型类。。包括excel2007 csv 文件等
$PHPExcel = $PHPReader->load('31excel5.xls');  //加载要读取的文件
$currentSheet = $PHPExcel->getSheet(0);      //取文件中的第一个表
$allColumn = $currentSheet->getHighestColumn();  //获取列数
$allRow = $currentSheet->getHighestRow();      //获取行数
for($currentRow = 1; $currentRow<=$allRow; $currentRow++){  //通过所有行数和列数循环读取表中的所有值
   for($currentColumn='A'; $currentColumn<=$allColumn; $currentColumn++){  
    $address = $currentColumn.$currentRow;  
    echo $currentSheet->getCell($address)->getValue()."\t";  //输出取到的表格中的值
   }
   echo "\n";
}