从PHPExcel中的行和列索引获取列名 [英] Getting the Name of a Column from the row and column indexes in PHPExcel

查看:324
本文介绍了从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

这篇关于从PHPExcel中的行和列索引获取列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆