You are here

function socialcalc_coord_to_cr in Sheetnode 5

Same name and namespace in other branches
  1. 6 socialcalc.inc \socialcalc_coord_to_cr()
  2. 7.2 socialcalc.inc \socialcalc_coord_to_cr()
  3. 7 socialcalc.inc \socialcalc_coord_to_cr()
4 calls to socialcalc_coord_to_cr()
socialcalc_parse_edit in ./socialcalc.inc
socialcalc_parse_sheet in ./socialcalc.inc
theme_sheetnode_range in ./sheetnode.module
_sheetnode_phpexcel_import_do in modules/sheetnode_phpexcel/sheetnode_phpexcel.import.inc

File

./socialcalc.inc, line 623
SocialCalc manipulation functions Translated from socialcalc-3.js and companion files

Code

function socialcalc_coord_to_cr($coord) {
  static $coord_to_cr = array();
  if (isset($coord_to_cr[$coord])) {
    return $coord_to_cr[$coord];
  }
  $c = 0;
  $r = 0;
  for ($i = 0; $i < strlen($coord); $i++) {

    // this was faster than using regexes; assumes well-formed
    $ch = ord(substr($coord, $i, 1));
    if ($ch == 36) {
    }
    else {
      if ($ch <= 57) {
        $r = 10 * $r + $ch - 48;
      }
      else {
        if ($ch >= 97) {
          $c = 26 * $c + $ch - 96;
        }
        else {
          if ($ch >= 65) {
            $c = 26 * $c + $ch - 64;
          }
        }
      }
    }
  }
  $coord_to_cr[$coord] = array(
    $c,
    $r,
  );
  return $coord_to_cr[$coord];
}