Announcement

Collapse
No announcement yet.

TStringGrid in Excel exportieren

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • TStringGrid in Excel exportieren

    Wie kann ich Daten von einem TStringGrid in Excel exportieren?
    und wie kann ich diese Daten sofort in Excel anzeigen lassen?

    Vielen Dank für die Unterstützung im voraus.

    Sebastian

  • #2
    Hallo Sebastian,

    wenn es nur darum geht die Daten in eine bestehende Exceltabelle zu bekommen, ohne großartige COM-Programmierung zu machen, dann kann man auch auf eine einfache DDE-Verbindung mit einem TDdeClientConv zurückreifen.
    <pre><code>
    object Form1: TForm1
    Left = 197
    Top = 108
    Width = 696
    Height = 480
    Caption = 'Form1'
    Color = clBtnFace
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    OldCreateOrder = False
    PixelsPerInch = 96
    TextHeight = 13
    object StringGrid1: TStringGrid
    Left = 36
    Top = 40
    Width = 320
    Height = 201
    ColCount = 3
    TabOrder = 0
    OnDrawCell = StringGrid1DrawCell
    OnSelectCell = StringGrid1SelectCell
    end
    object Edit1: TEdit
    Left = 372
    Top = 40
    Width = 121
    Height = 21
    TabOrder = 1
    Text = 'Edit1'
    end
    object DdeClientConv1: TDdeClientConv
    ServiceApplication = 'Excel'
    DdeService = 'Excel'
    DdeTopic = 'Mappe1'
    Left = 372
    Top = 68
    LinkInfo = (
    'Service Excel'
    'Topic Mappe1')
    end
    end

    procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
    ARow: Integer; var CanSelect: Boolean);
    begin
    StringGrid1.Cells[ACol, ARow] := Edit1.Text;
    end;

    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
    Rect: TRect; State: TGridDrawState);
    var
    Item: string;
    Data: string;
    begin
    Item := 'Z' + IntToStr(ARow) + 'S' + IntToStr(ACol);
    Data := StringGrid1.Cells[ACol, ARow] + #0;
    DdeClientConv1.PokeData(Item, @Data[1]);
    end;

    </pre></code>

    Das Bsp. stellt die Werte aus dem Stringgrid an der gleichen Stelle in Excel dar.

    Gruß Fal
    Wenn du denkst du hast alle Bugs gefunden, dann ist das ein Bug in deiner Denksoftware.

    Quellcode ohne ein Mindestmaß an Formatierung sehe ich mir nicht an! Ich leiste keinen Privatsupport per Mail oder PN!

    Comment

    Working...
    X