Подтвердить что ты не робот

PHPExcel, как получить индекс столбца из ячейки

PHPExcel $cell- > getColumn() возвращает 'A', 'B', 'C',...

что является лучшим способом получить целое число (0, 1, 2,...) из ячейки.

Эта функция не существует.

$colIndex = $cell->getColumnIndex();

Итак, какова альтернатива tooput преобразования chr в ascii?

4b9b3361

Ответ 1

$colIndex = PHPExcel_Cell::columnIndexFromString($cell->getColumn());

Ответ 2

Вы можете получить индекс столбца во время итерации.

$xls = PHPExcel_IOFactory::load($fn);
$xls->setActiveSheetIndex(0);
$sheet = $xls->getActiveSheet();

foreach($sheet->getRowIterator() as $row)
{
    foreach($row->getCellIterator() as $key => $cell)
    {
        echo $key; // 0, 1, 2...
        echo $cell->getCalculatedValue(); // Value here
    }
}

Ответ 3

If you want to get decrement cell address using this function, you have to use another function with this function as follows.

<?php
echo columnLetter("AB");

function columnLetter($c){


$letter="";
    $c = intval(columnNumber($c));
    if ($c<=0) return '';

    while($c != 0){
       $p = ($c - 1) % 26;
       $c = intval(($c - $p) / 26);
       $letter = chr(65 + $p) . $letter;
    }

    return $letter;

}

function columnNumber($col){

    $col = str_pad($col,2,'0',STR_PAD_LEFT);
    $i = ($col{0} == '0') ? 0 : (ord($col{0}) - 64) * 26;
    $i += ord($col{1}) - 64;

    return $i-1;

}
?>