Einzelnen Beitrag anzeigen

Keldorn

Registriert seit: 6. Mär 2003
Ort: Meißen
876 Beiträge
 
Delphi 10.1 Berlin Professional
 
#2

Re: String Grid nach Excel kopieren

  Alt 11. Okt 2009, 14:32
Hallo,

du kannst mal das probieren:

Delphi-Quellcode:
procedure Proc_Stringgrid_GridInhaltInZwischenablageKopieren(Grid:TStringgrid);
var arow,acol:integer;
    sl:Tstrings;
    s:string;
  begin
    sl:=TStringList.Create;
    try
    with Grid do
      begin
        for arow:=0 to RowCount-1 do
          begin
            s:='';
            for acol:=0 to ColCount-1 do
              begin
                if acol=ColCount-1 then
                  s:=s+cells[acol,arow]
                 else
                  s:=s+cells[acol,arow]+chr(vk_tab)
              end;
            sl.Add(s);
          end;
      end;
    Clipboard.SetTextBuf(pchar(sl.Text+#0));
    finally
      sl.Free;
    end;
  end;

procedure Proc_Stringgrid_GridInhaltAusZwischenablageEinfuegen(Grid:TStringgrid);
var arow,acol,i:integer;
    sl:Tstrings;
    s:string;
    arr:TSTringdynarray;
  begin
    sl:=TStringList.Create;

    try
    sl.text:=Clipboard.AsText;
    with Grid do
      begin
        rowcount:=sl.count+fixedrows;
        arow:=FixedRows;
        for i:=0 to sl.Count - 1 do
          begin
            rows[arow].clear;
            arr:=Func_Explode(chr(vk_tab),sl[i]);

            for acol:=0 to high(arr) do
              begin
                if acol<=colcount-1 then
                  cells[acol,arow]:=arr[acol];
              end;
            inc(arow);
          end;
      end;

    finally
      sl.Free;
    end;
  end;
- func_explode: such mal hier im Forum nach Hier im Forum suchenexplode
- aus der Zwischenablage: Colcount wird nicht gesetzt, das benötige ich nicht.
- Export ist alles mit fixedrows, import nur die "Daten".

Gruß Frank

Lükes Grundlage der Programmierung:
Es wird nicht funktionieren
(Murphy)
  Mit Zitat antworten Zitat