【问题标题】:How to get the excel column number from column name in php?如何从php中的列名获取excel列号?
【发布时间】:2019-11-01 05:10:28
【问题描述】:

我正在编写与 excel 文档相关的脚本,因此我需要从列字母(即列名)中获取列索引。 为此,我不想使用 PHP Excel 库,因为我正在处理单行代码。

例如需要这样的结果:-

   A => 1 
   B => 2 
   AA => 27 
   AB => 28 
   EC => 132
   UMX  => 14558

【问题讨论】:

标签: php phpexcel


【解决方案1】:

这是从列标题字母获取索引的解决方案:-

public function letters2numbers($columnName) {
    $value = 0;
      $len = (strlen($columnName)-1);
    for ($i = 0; $i <= $len; $i++) {
       $delta = intval( ord($columnName[$i])  - 64);
       $value = intval($value*26)+ intval($delta);   
    } 
    return $value;
}

【讨论】:

    猜你喜欢
    • 2013-10-09
    • 2013-07-16
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-23
    相关资源
    最近更新 更多