从PHPExcel中的行和列索引获取列名

问题描述:

我想知道是否可以从行索引和列索引中获取列的名称.即我想拥有一个通过传递行索引和列索引来返回列名称的函数,例如,假设我的函数名称为getColumnName.如果我输入getColumnName(1,8),我希望它为我返回B8.

I want to know if it is possible to get the name of a column from the row and column indexes. i.e I want to have a function that would return the name of a column by passing the row index and the column index e.g let's say the name of my function is getColumnName. If I type getColumnName(1,8), I want it to return B8 for me.

看看PHPExcel_Cell :: stringFromColumnIndex()方法.

Take a look at the PHPExcel_Cell::stringFromColumnIndex() method.

这接受一个数字参数,例如1或255,并会返回相应的列字母,例如基于列0​​为'A'的'B'或'IV'并且行从1开始.

This accepts a numeric argument, e.g. 1 or 255, and will return the corresponding column letter, e.g. 'B' or 'IV' based on column 0 being 'A' and rows start from 1.

编辑

如果仅需要此参数来设置单元格值,则大多数单元格操作功能(如

If you only need this for setting cell values, then most cell manipulation functions such as

setCellValue()

具有类似的方法

setCellValueByColumnAndRow()

接受行号和列号而不是单元格地址

that accept a row and column number rather than a cell address