如何按标题获取单元格值?不是数字索引(phpexcel)



在我的项目的当前版本中,我只能使用getCell("A4")->getValue()获取单元格值,但有一个问题,有时我想删除或添加一列,它会破坏其他值,所以我必须再次对数据进行排序。我想知道是否有一个函数,可以用一个数字代替一个字母来给我一个单元格,例如:$title中的"A4"["第一个"][4]和$title["第二个"][5]中的"B5"示例的图像

也许我的表达不够清晰,我希望你能理解我的观点/问题,谢谢!

$colunmn=1; //The colunmn  you want to start the cicle 
$columnMax=5; //The colunmn  you want to end the cicle 
while($coluna < $columnMax){
$colunmString = PHPExcel_Cell::stringFromColumnIndex($colunmn); //Convert the nº index into a collunm string ex: 1->'A', 2->'B', 27->'AA', 28->'AB'
getCell($colunmString. "2")->getValue(); //I used "2" as a line exemple you can change it
$colunmString++;
}

您可以根据需要调整代码。只需使用函数PHPExcel_Cell::stringFromColumnIndex( int )来获取具有int索引的列字符串。

最新更新