读书人

EXCEL列名成是第列解决方法

发布时间: 2013-04-02 12:35:26 作者: rapoo

EXCEL列名成是第列
各位:
在做EXCEL出,我想做一函,通坐可以得到是在第列,比方:A是第一列,B是第二列…………Z是第26列,AA2是27列,求算法。了。
[解决办法]
function TForm1.GetColNum(aColName: string): Integer;
var
I,tmpLen : Integer;
begin
tmpLen := Length(aColName);
Result := 0;
for I := 1 to tmpLen do begin
if tmpLen - I > 0 then
Result := Result + Trunc((Ord(aColName[I]) - 64) * Power(26,tmpLen - I ))
else
Result := Result + Trunc(Ord(aColName[I]) - 64);
end;
end;

读书人网 >.NET

热点推荐