title: Convert an excel or spreadsheet column letter to its number in Pythonic fashion
body: <p>Is there a more pythonic way of converting excel-style columns to numbers (starting with 1)?</p>
  
  <p>Working code up to two letters:</p>
  
  <pre class="lang-py prettyprint-override"><code>def column_to_number(c):
      """Return number corresponding to excel-style column."""
      number=-25
      for l in c:
          if not l in string.ascii_letters:
              return False
          number+=ord(l.upper())-64+25
      return number
  </code></pre>
  
  <p>Code runs:</p>
  
  <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; column_to_number('2')
  False
  &gt;&gt;&gt; column_to_number('A')
  1
  &gt;&gt;&gt; column_to_number('AB')
  28
  </code></pre>
  
  <p>Three letters not working.</p>
  
  <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; column_to_number('ABA')
  54
  &gt;&gt;&gt; column_to_number('AAB')
  54
  </code></pre>
  
  <p>Reference:  <a href="https://stackoverflow.com/questions/667802/what-is-the-algorithm-to-convert-an-excel-column-letter-into-its-number">question answered in C#</a></p>