简体   繁体   English

PHPexcel如何获取当前单元格号

[英]PHPexcel how to get the current cell number

I am displaying a set of data using rangeToArray() on PHPexcel library that works fine. 我正在PHPexcel库上使用rangeToArray()显示一组数据,效果很好。 each data is unique so i need to run another function per data, to do this i have to supply the current cell number to run my function. 每个数据都是唯一的,因此我需要为每个数据运行另一个功能,为此,我必须提供当前的单元号才能运行我的功能。

$mySet = $objPHPExcel->getActiveSheet()->rangeToArray('A1:J31');

foreach ($mySet as $row) {
    echo "<tr>";
    foreach ($row as $data) {

        echo "<td>".$data."</td>";

    }
    echo "</tr>";
}

My question is how can i get the current cell number of each data iteration? 我的问题是如何获取每个数据迭代的当前单元格编号?

By default, rangeToArray() returns a simple enumerated array; 默认情况下, rangeToArray()返回一个简单的枚举数组; but if you look at the arguments for the method 但是如果您查看方法的参数

/**
 * Create array from a range of cells
 *
 * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
 * @param mixed $nullValue Value returned in the array entry if a cell doesn't exist
 * @param boolean $calculateFormulas Should formulas be calculated?
 * @param boolean $formatData Should formatting be applied to cell values?
 * @param boolean $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero
 *                               True - Return rows and columns indexed by their actual row and column IDs
 * @return array
 */

The last argument allow you to return that array indexed by row and column: 最后一个参数允许您返回按行和列索引的数组:

$mySet = $objPHPExcel->getActiveSheet()->rangeToArray('A1:J31', null, true, true, true);

foreach ($mySet as $rowNumber => $row) {
    echo "<tr>";
    foreach ($row as $columnAddress => $data) {

        echo "<td>".$columnAddress.$rowNumber.' = '.$data."</td>";

    }
    echo "</tr>";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM