Getting the Name of a Column from the row and column indexes in PHPExcel

僤鯓⒐⒋嵵緔 提交于 2019-12-23 08:10:08

问题


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.


回答1:


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

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.

EDIT

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

setCellValue()

have a corresponding method like

setCellValueByColumnAndRow()

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



来源:https://stackoverflow.com/questions/5536964/getting-the-name-of-a-column-from-the-row-and-column-indexes-in-phpexcel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!