Skip to content

Commit e4a65bb

Browse files
committed
Add column binary
1 parent 6df4227 commit e4a65bb

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
Ask a range
2525

26+
### Column
27+
28+
Convert column name to int (A --> 1, AA --> 27, ...)
29+
2630
### Ask
2731

2832
Test of interactive prompt

bin/column.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require_once("require.php");
5+
6+
use Tools\Exec\Executable;
7+
use Tools\Exec\Params;
8+
9+
$callback = function($args, $opts, $console) {
10+
$column = str_split($args[0]);
11+
12+
$values = array_map(function($column, $index) { return ($index * (ord('Z') - ord('A'))) + ord(strtoupper($column)) - ord('A') + 1; }, $column, array_keys($column));
13+
14+
$console->print(array_reduce($values, function($carry, $item) { return $carry += $item; }, 0));
15+
};
16+
17+
$params = new Params([
18+
"requiredParams" => 1,
19+
(object) [
20+
"key" => "usage",
21+
"value" => "USAGE : " . __FILE__ . " column"
22+
],
23+
(object) [
24+
"key" => "callback",
25+
"value" => $callback
26+
]
27+
]);
28+
29+
$exec = new Executable($params);
30+
$exec->run($argc, $argv);

0 commit comments

Comments
 (0)