关于phpexcel读取excel表的问题,如下

2025-03-07 03:52:33
推荐回答(1个)
回答1:

$sheet_i = 2;//行
$sheet_j = 1;//列
for($currentRow = 2;$currentRow <= $allRow;$currentRow++){
/**从第A列开始输出*/
for($currentColumn= 'A';$currentColumn<= $allColumn; $currentColumn++){
$val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue();/**ord()将字符转为十进制数*/
if($sheet_i = 2&&$sheet_j = 1)//自己算好输出第几行第几列
{
if($currentColumn == 'A')
{
echo GetData($val)."\t";
}else{
//echo $val;
/**如果输出汉字有乱码,则需将输出内容用iconv函数进行编码转换,如下将gb2312编码转为utf-8编码输出*/
echo iconv('utf-8','gb2312', $val)."\t";
}
}
$sheet_j ++;
}
$sheet_i++;
$sheet_j = 0;//重置列数
echo "
";
}
echo "\n";

?>