Einzelnen Beitrag anzeigen

Trille

Registriert seit: 25. Sep 2007
62 Beiträge
 
#1

Problem beim Formatieren einer Word-Tabelle

  Alt 21. Mär 2009, 10:02
Hallo allerseits, ich experimentiere momentan etwas mit Delphi und Word herum. Nun habe ich folgendes Problem:

Ich füge einem worddokument eine Tabelle hinzu, das funktioniert super. Nun möchte ich diese Tabelle folgendermaßen formatieren:


// Tabelle hinzufügen
Delphi-Quellcode:
curTable := WordDocument.Tables.Add(WordApplication.Selection.Range,100,3,_DefaultTableBehavior,_AutoFitBehavior);
        
        curTable.Cell(1, 1).Range.Font.Name := 'Arial';
        curTable.Cell(1, 1).Range.Font.Size := 8;
        curTable.Cell(1, 1).Range.Font.Color := clRed;
        curTable.Cell(1, 1).Range.Text := 'Test';
Das funktioniert auch bestens.

Jetzt probiere ich folgendes:
Delphi-Quellcode:
curTable := WordDocument.Tables.Add(WordApplication.Selection.Range,100,3,_DefaultTableBehavior,_AutoFitBehavior);
        FormatTableHeader(curTable, 'Arial', 8, clRed);


procedure TMainForm.FormatTableHeader(var tab: Table; font: TFontName; fontSize: Integer; color: Cardinal);
var
    i: integer;
begin
        tab.Cell(1, 1).Range.Font.Name := font;
        tab.Cell(1, 1).Range.Font.Size := fontSize;
        tab.Cell(1, 1).Range.Font.Color := color;

        // temp
        tab.Cell(1, 1).Range.Text := 'Test';
end;
Jetzt fliegt mir entweder die Anwendung um die Ohren oder es wird irgendeine Zelle formatiert.
Was mache ich falsch?

Vielen Dank!
  Mit Zitat antworten Zitat