Translate

2013/12/26

Convert Excel column to integer funtion with Delphi

See also: How to convert a column number (eg. 127) into an excel column (eg. AA)


Delphi code below:
function ColumnNumber(A_ColAddress: string): Integer;
var
  _Digits: array of Integer;
  _Pos: Integer;
  _Mul, _Res: Integer;
begin
  SetLength(_Digits, Length(A_ColAddress));
  for _Pos := 0 to Length(A_ColAddress)-1 do
  begin
    _Digits[_Pos] := Ord(A_ColAddress[_Pos+1]) - 64;
  end;

  _Mul := 1;
  _Res := 0;
  for _Pos := Length(A_ColAddress)-1 downto 0 do
  begin
    _Res := _Res + (_Digits[_Pos] * _Mul);
    _Mul := _Mul * 26;
  end;

  Result := _Res;
end;

沒有留言:

張貼留言

DataSnap REST API Authorization with PHP

About Authentication with DataSet REST JavaScript client. In connection.js: function setCredentials(user, password) { connectionInf...