Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi String Grid nach Excel kopieren (https://www.delphipraxis.net/141562-string-grid-nach-excel-kopieren.html)

Dumpfbacke 11. Okt 2009 12:58


String Grid nach Excel kopieren
 
Hallo,
ich möchte die Daten eines String Grid nach Excel kopieren. Am liebsten wäre es mir wenn es mit STRG C im String Grid und STRG V in Excel gehen würde. Leider geht das nicht. Kann mir hier jemand helfen ?

Tanja :angel:

Keldorn 11. Okt 2009 14:32

Re: String Grid nach Excel kopieren
 
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


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:58 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz