用Delphi 将 Excel 列名转 0 起 数值

2016-10-13 10:26:34来源:oschina作者:vga人点击



```
function GetColNum(aColName: string): Integer;
//Excel 单元格 行列值 如: AI -> 34
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;
Dec(Result); // xlsreadwrite列是从 0 开始
end;
function GetColAndRow(ColAndRowStr: string): TPoint;
var
i, x, y: Integer;
str: string;
begin
Result := Point(0, 0);
for i := 1 to Length(ColAndRowStr) do
begin
if ColAndRowStr[i] in ['0'..'9'] then
begin
str := UpperCase(Copy(ColAndRowStr, 1, i-1));
x := GetColNum(str);
y := StrToInt(Copy(ColAndRowStr,i, 255));
Result := POint(x, y);
Exit;
end;
end;
end;
```

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台