Einzelnen Beitrag anzeigen

aaron

Registriert seit: 18. Feb 2003
202 Beiträge
 
Delphi 2007 Professional
 
#1

Stringgrid nach Tabelle in Word

  Alt 23. Mär 2008, 18:14
Hallo
ich versuche ein Stringgrid in eine Tabelle in Word zu kopieren:
Delphi-Quellcode:
procedure Tform1.AdvGlowButton3Click(Sender: TObject);

var
  WordApp, NewDoc, WordTable: OLEVariant;
  iRows, iCols, iGridRows, jGridCols: Integer;
begin
  try
    // Create a Word Instance
    // Word Instanz erzeugen
    WordApp := CreateOleObject('Word.Application');
  except
    // Error...
    // Fehler....
    Exit;
  end;

  // Show Word
  // Word anzeigen
  WordApp.Visible := True;

  // Add a new Doc
  // Neues Dok einfügen
  NewDoc := WordApp.Documents.Add;

  // Get number of columns, rows
  // Spalten, Reihen ermitteln
  iCols := StringGrid1.ColCount;
  iRows := StringGrid1.RowCount;

  // Add a Table
  // Tabelle einfügen
  WordTable := NewDoc.Tables.Add(WordApp.Selection.Range, iCols, iRows);

  // Fill up the word table with the Stringgrid contents
  // Tabelle ausfüllen mit Stringgrid Daten
  for iGridRows := 1 to iRows do
    for jGridCols := 1 to iCols do
      WordTable.Cell(iGridRows, jGridCols).Range.Text :=
        StringGrid1.Cells[jGridCols - 1, iGridRows - 1];

  // Here you might want to Save the Doc, quit Word...
  // Hier evtl Word Doc speichern, beenden...

  // ...
  
  // Cleanup...
  WordApp := Unassigned;
  NewDoc := Unassigned;
  WordTable := Unassigned;
end;
Ich bekomme in Word immer nur die erste und die letzte Zeile eingefügt und auch immer so gestaucht, würde ich den Spalten gerne individuelle Breiten geben und einen schwarzen Rand.

Frohe Ostern
Aaron
  Mit Zitat antworten Zitat