Einzelnen Beitrag anzeigen

Hermann85

Registriert seit: 24. Jan 2008
Ort: Dresden
42 Beiträge
 
#11

Re: Excel-Sheet mit Delphi verändern

  Alt 11. Jan 2010, 09:56
Hallo,
Hab mal eine schöne Function im Netz gefunden, die das Problem behandelt:

Delphi-Quellcode:
// Hilfsfunktion
(*Wandelt Buchstaben-Zahlenkombination in eine ZellenReferenz für Excel um*)
function RefToCell(RowID, ColID : Integer): string;
var ACount, APos : Integer;
begin
  ACount := ColID div 26;
  APos := ColID mod 26;
  if APos = 0 then
  begin
    ACount := ACount-1;
    APos := 26;
  end;
  if ACount = 0 then
  begin
    Result := Chr(Ord('A') + ColID -1) + IntToStr(RowID);
  end;
  if ACount = 1 then
  begin
    Result := 'A' + Chr(Ord('A') + APos -1) + IntToStr(RowID);
  end;
  if ACount > 1 then
  begin
    Result := Chr(Ord('A') + ACount -1) + Chr(Ord('A') + APos - 1) + IntToStr(RowID);
  end;
end;

Gruß Hermann
  Mit Zitat antworten Zitat