Форум: "Начинающим";
Текущий архив: 2009.11.08;
Скачать: [xml.tar.bz2];
Внизпоиск ячеек по excel файлам Найти похожие ветки
← →
Сергей М. © (2009-09-24 13:36) [40]
> это будет завтра
В смысле ?)
← →
Thrashead (2009-09-24 13:36) [41]function FunctionX(s: String): String;
var
i, p, n1, n2: Integer = 0;
t, t1, t2, t11, t21, t3: String = "";
procedure GetParts(a: String; var b: String; var c: Integer);
var
j: Integer = 0;
FDP: Integer = 0; // First Digit Position
tt: String = "";
begin
b:="";
c:=0;
if a<>"" then
for j:=1 to Length(a) do
if a[j] in ["0".."9"] then
if FDP=0 then FDP:=j;
if FDP>1 then
begin
b:=Copy(a,1,FDP-1);
try
c:=StrToInt(Copy(a,FDP,Length(a)-FDP+1));
except
end;
end;
end;
function GetNextLetters(a: String): String;
var
tt: String;
j: Integer;
IncLetter: Boolean = True;
begin
tt:=UpperCase(a);
Result:=tt;
for j:=Length(tt) downto 1 do
begin
if IncLetter then
if tt[j] in ["A".."Z"] then
if tt[j]="Z" then
begin
Result[j]:="A";
if j=1 then Result:="A"+Result;
end
else
begin
Result[j]:=Chr(Ord(Result[j])+1);
IncLetter:=False;
end;
end;
end;
begin
Result:="";
p:=Pos(":",s);
if (p>0) and (p<Length(s)) then
begin
t:=UpperCase(s);
t1:=Copy(t,1,p-1);
t2:=Copy(t,p+1,Length(t)-p);
if (t1<>"") and (t2<>"") then
begin
GetParts(t1,t11,n1);
GetParts(t2,t21,n2);
// TEST Result:=t1+"-"+t11+"-"+IntToStr(n1)+" / "+t2+"-"+t21+"-"+IntToStr(n2);
if (t11<>"") and (t21<>"") and (n1>0) and (n2>0) and (n1<=n2) then
if (t11<t21) then
begin
t3:=t11;
i:=n1;
while t3<>t21 do
begin
for i:=n1 to n2 do
Result:=Result+t3+IntToStr(i)+",";
t3:=GetNextLetters(t3);
end;
for i:=n1 to n2 do Result:=Result+t21+IntToStr(i)+",";
Result:=Copy(Result,1,Length(Result)-1);
end;
if (t11=t21) and (n1<n2) then
begin
for i:=n1 to n2 do Result:=Result+t11+IntToStr(i)+",";
Result:=Copy(Result,1,Length(Result)-1);
end;
end;
end;
end;
procedure Button1OnClick(Sender: TfrxComponent);
begin
Edit1.Text:=FunctionX("a1:aaa3");
end;
← →
Thrashead (2009-09-24 13:41) [42]сейчас, силя на работе, наваял кусок кода.
протестировано в fastreport.
много букв, т.к. сделаны некоторые проверки на возможные ошибки в строке.
+обрабатывает excel"евские AA,AB, AZ, AAA и т.п.
знаю, что в экселе нет AAA (IV предел) - но сделал универсально.
применимо только к строкам с двоеточием (см. код).
хз что ещё добавить.
вроде работает.
← →
Thrashead (2009-09-24 13:42) [43]хммм... опечатка. "сиДя на работе".
← →
kate158 © (2009-09-24 14:54) [44]Сергей М. спасибо!
Thrashead спасибо! код - то, что нужно.
:)
← →
Thrashead (2009-09-24 15:01) [45]Наздоровье :)
Ещё интересные задачки будут?
Страницы: 1 2 вся ветка
Форум: "Начинающим";
Текущий архив: 2009.11.08;
Скачать: [xml.tar.bz2];
Память: 0.54 MB
Время: 0.008 c