#NEWLINE# def column_index_from_string( column , fast = False ) : #NEWLINE# #INDENT# 'Convert a column letter into a column number (e.g. B -> 2)\n\n    Excel only supports 1-3 letter column names from A -> ZZZ, so we\n    restrict our column names to 1-3 characters, each in the range A-Z.\n\n    .. note::\n\n        Fast mode is faster but does not check that all letters are capitals between A and Z\n\n    ' #NEWLINE# column = column . upper ( ) #NEWLINE# clen = len ( column ) #NEWLINE# if ( ( not fast ) and ( not all ( ( ( 'A' <= char <= 'Z' ) for char in column ) ) ) ) : #NEWLINE# #INDENT# msg = ( 'Column string must contain only characters A-Z: got %s' % column ) #NEWLINE# raise ColumnStringIndexException ( msg ) #NEWLINE# #UNINDENT# if ( clen == 1 ) : #NEWLINE# #INDENT# return ( ord ( column [ 0 ] ) - 64 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( clen == 2 ) : #NEWLINE# #INDENT# return ( ( ( 1 + ( ord ( column [ 0 ] ) - 65 ) ) * 26 ) + ( ord ( column [ 1 ] ) - 64 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( clen == 3 ) : #NEWLINE# #INDENT# return ( ( ( ( 1 + ( ord ( column [ 0 ] ) - 65 ) ) * 676 ) + ( ( 1 + ( ord ( column [ 1 ] ) - 65 ) ) * 26 ) ) + ( ord ( column [ 2 ] ) - 64 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( clen > 3 ) : #NEWLINE# #INDENT# raise ColumnStringIndexException ( 'Column string index can not be longer than 3 characters' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ColumnStringIndexException ( 'Column string index can not be empty' )