Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Positionierung von Textbox in Worddokument über Delphi (https://www.delphipraxis.net/157915-positionierung-von-textbox-worddokument-ueber-delphi.html)

luckystar85 29. Jan 2011 15:18

Positionierung von Textbox in Worddokument über Delphi
 
Hi,
ich habe über RAD 2009 ein Programm erstellt das per Exportfunktion ein Word-Dokument über OLE generiert. Dazu soll in der Kopfzeile eine Textbox integriert werden, in der das Thema steht. Ich habe alles erstellt und unter Office 2010 funktioniert das alles fehlerfrei. Nur unter Office 2003 ist die Textbox nicht an der Stelle positioniert wie unter Office 2010. Ich habe auch schon versucht, wenn es Office 2003 ist, die Textbox einfach um 20-30 Pixel nach oben zu schieben aber auch das funktioniert nicht. Die Textbox bleibt immer an der gleichen Position. Per Mausaktion kann ich sie aber problemlos an die richtig Stelle verschieben.

Hier mein Code:
Delphi-Quellcode:
Procedure InsertWordTextBox(Const AWordApplication : TWordApplication; Const ALeft, ATop, AWidth, AHeight : Double);
Begin
  AWordApplication.Selection.HeaderFooter.Shapes.AddTextbox(msoTextOrientationHorizontal, ALeft, ATop, AWidth, AHeight, EmptyParam).Select(EmptyParam);
  AWordApplication.Selection.ShapeRange.TextFrame.TextRange.Select;
  AWordApplication.Selection.Collapse(EmptyParam);
  AWordApplication.Selection.ShapeRange.Fill.Visible              := msoFalse;
  AWordApplication.Selection.ShapeRange.Line.Visible              := msoFalse;
  AWordApplication.Selection.ShapeRange.Line.Weight               := 0.75;
  AWordApplication.Selection.ShapeRange.Line.DashStyle            := msoLineSolid;
  AWordApplication.Selection.ShapeRange.Line.Style                := msoLineSingle;
  AWordApplication.Selection.ShapeRange.Line.Transparency         := 0;
  AWordApplication.Selection.ShapeRange.Line.Visible              := msoFalse;
  AWordApplication.Selection.ShapeRange.LockAspectRatio           := msoFalse;
  AWordApplication.Selection.ShapeRange.TextFrame.MarginLeft      := 0;
  AWordApplication.Selection.ShapeRange.TextFrame.MarginRight     := 0;
  AWordApplication.Selection.ShapeRange.TextFrame.MarginTop       := 0;
  AWordApplication.Selection.ShapeRange.TextFrame.MarginBottom    := 0;
  AWordApplication.Selection.ShapeRange.RelativeHorizontalPosition := wdRelativeHorizontalPositionPage;
  AWordApplication.Selection.ShapeRange.RelativeVerticalPosition  := wdRelativeVerticalPositionPage;
  AWordApplication.Selection.ShapeRange.Left                      := ALeft;
  AWordApplication.Selection.ShapeRange.Top                       := ATop;
  AWordApplication.Selection.ShapeRange.WrapFormat.Side           := wdWrapBoth;
  AWordApplication.Selection.ShapeRange.WrapFormat.DistanceTop    := AWordApplication.CentimetersToPoints(0);
  AWordApplication.Selection.ShapeRange.WrapFormat.DistanceBottom := AWordApplication.CentimetersToPoints(0);
  AWordApplication.Selection.ShapeRange.WrapFormat.DistanceLeft   := AWordApplication.CentimetersToPoints(0.32);
  AWordApplication.Selection.ShapeRange.WrapFormat.DistanceRight  := AWordApplication.CentimetersToPoints(0.32);
  AWordApplication.Selection.ShapeRange.WrapFormat.type_           := 3;
  AWordApplication.Selection.ShapeRange.TextFrame.AutoSize        := Integer(False);
  AWordApplication.Selection.ShapeRange.TextFrame.WordWrap        := Integer(True);
End;

omata 29. Jan 2011 18:13

AW: Positionierung von Textbox in Worddokument über Delphi
 
Hast du mal in Office 2003 die Textboxerstellung mit dem Makrorekorder aufgezeichnet? Gibt es da Unterschiede zu deinen bisherigen Befehlen und wenn ja welche?

Bummi 29. Jan 2011 18:27

AW: Positionierung von Textbox in Worddokument über Delphi
 
@omata
wollte ich auch antworten, habe dann aber festgestellt daß die Mausaktionen bzgl. Textboxen beim Aufzeichnen von Macros scheinbar nicht so ohne weiteres erreichbar sind.

luckystar85 29. Jan 2011 18:44

AW: Positionierung von Textbox in Worddokument über Delphi
 
Ja versucht habe ich das, aber wie schon Bummi geschrieben hat, ist das bei Office 2003 leider nciht so einfach machbar. Während die Makro-Aufzeichnung läuft ist die Maussteuerung eingeschränkt.

sx2008 29. Jan 2011 19:11

AW: Positionierung von Textbox in Worddokument über Delphi
 
Folgendes ist mir aufgefallen:
Die Funktion AddTextbox() gibt ein Objekt zurück, mit dem man weiterarbeiten sollte.
Anstatt ständig über AWordApplication.Selection zuzugreifen, wäre es besser direkt mit dem Objekt zu arbeiten.
Natürlich muss man sich dazu in das Objektmodell von Word einarbeiten aber es lohnt sich.

luckystar85 29. Jan 2011 20:05

AW: Positionierung von Textbox in Worddokument über Delphi
 
Liste der Anhänge anzeigen (Anzahl: 2)
sx2008, vielen Dank für den Hinweis. Ich habe meinen Code darauf hin angepasst, leider ohne Erfolg. Ich habe eben auch noch gesehen das die Umsetzung des Linienstils nicht funktioniert. Bei dem Textfeld unter 2003 ist noch der Rahmen sichtbar. Habe unter 2003 auch ein Makro aufgezeichnet zum Ausblenen des Rahmens. Habe das denn in Delphi nachgebaut und auch die Funktion läuft unter 2003 nicht. Bei Office 2010 wie gehabt ohne Probleme.

Delphi-Quellcode:
Procedure InsertWordTextBox(Const AWordApplication : TWordApplication; Const ALeft, ATop, AWidth, AHeight : Double);
Var
  lTextBox : Word_TLB.Shape;
Begin
  lTextBox := AWordApplication.Selection.HeaderFooter.Shapes.AddTextbox(msoTextOrientationHorizontal, ALeft, ATop, AWidth, AHeight, EmptyParam);
  lTextBox.Select(EmptyParam);
  lTextBox.TextFrame.TextRange.Select;
  lTextBox.Fill.Visible              := msoFalse;
  lTextBox.Line.Visible              := msoFalse;
  lTextBox.Line.Weight               := 0.75;
  lTextBox.Line.DashStyle            := msoLineSolid;
  lTextBox.Line.Style                := msoLineSingle;
  lTextBox.Line.Transparency         := 0;
  lTextBox.Line.Visible              := msoFalse;
  lTextBox.LockAspectRatio           := msoFalse;
  lTextBox.TextFrame.MarginLeft      := 0;
  lTextBox.TextFrame.MarginRight     := 0;
  lTextBox.TextFrame.MarginTop       := 0;
  lTextBox.TextFrame.MarginBottom    := 0;
  lTextBox.RelativeHorizontalPosition := wdRelativeHorizontalPositionPage;
  lTextBox.RelativeVerticalPosition  := wdRelativeVerticalPositionPage;
  lTextBox.Left                      := ALeft;
  lTextBox.Top                       := ATop;
  lTextBox.WrapFormat.Side           := wdWrapBoth;
  lTextBox.WrapFormat.DistanceTop    := AWordApplication.CentimetersToPoints(0);
  lTextBox.WrapFormat.DistanceBottom := AWordApplication.CentimetersToPoints(0);
  lTextBox.WrapFormat.DistanceLeft   := AWordApplication.CentimetersToPoints(0.32);
  lTextBox.WrapFormat.DistanceRight  := AWordApplication.CentimetersToPoints(0.32);
  lTextBox.WrapFormat.type_           := 3;
  lTextBox.TextFrame.AutoSize        := Integer(False);
  lTextBox.TextFrame.WordWrap        := Integer(True);
End;

omata 30. Jan 2011 20:08

AW: Positionierung von Textbox in Worddokument über Delphi
 
Ich habe leider nur Office 2000 und Office 2007 zum testen. Aber folgendes bringt bei beiden Versionen das selbe Ergebnis:

Delphi-Quellcode:

uses WordXP;

procedure InsertWordTextBox(const AWordApplication : TWordApplication;
                            const ALeft, ATop, AWidth, AHeight : Double);
const
  msoTextOrientationHorizontal = 1;
  msoFalse = 0;
  msoLineSolid = 1;
  msoLineSingle = 1;
var
  lTextBox : OleVariant;
begin
  lTextBox := AWordApplication.Selection.HeaderFooter.Shapes.AddTextbox(
    msoTextOrientationHorizontal, ALeft, ATop, AWidth, AHeight, EmptyParam
  );
  lTextBox.Select(EmptyParam);
  lTextBox.TextFrame.TextRange.Select;
  lTextBox.Fill.Visible := msoFalse;
  lTextBox.Line.Visible := msoFalse;
  lTextBox.Line.Weight := 0.75;
  lTextBox.Line.DashStyle := msoLineSolid;
  lTextBox.Line.Style := msoLineSingle;
  lTextBox.Line.Transparency := 0;
  lTextBox.Line.Visible := msoFalse;
  lTextBox.LockAspectRatio := msoFalse;
  lTextBox.TextFrame.MarginLeft := 0;
  lTextBox.TextFrame.MarginRight := 0;
  lTextBox.TextFrame.MarginTop := 0;
  lTextBox.TextFrame.MarginBottom := 0;
  lTextBox.RelativeHorizontalPosition := wdRelativeHorizontalPositionPage;
  lTextBox.RelativeVerticalPosition := wdRelativeVerticalPositionPage;
  lTextBox.Left := ALeft;
  lTextBox.Top := ATop;
  lTextBox.WrapFormat.Side := wdWrapBoth;
  lTextBox.WrapFormat.DistanceTop := AWordApplication.CentimetersToPoints(0);
  lTextBox.WrapFormat.DistanceBottom := AWordApplication.CentimetersToPoints(0);
  lTextBox.WrapFormat.DistanceLeft := AWordApplication.CentimetersToPoints(0.32);
  lTextBox.WrapFormat.DistanceRight := AWordApplication.CentimetersToPoints(0.32);
  lTextBox.WrapFormat.Type := 3;
end;

procedure TForm.ButtonClick(Sender: TObject);
var WordApplication:TWordApplication;
    Document:_Document;
begin
  WordApplication:=TWordApplication.Create(Self);
  try
    WordApplication.Connect;
    WordApplication.Visible:=true;
    Document:=WordApplication.Documents.Add(
      EmptyParam, EmptyParam, EmptyParam, EmptyParam
    );
    Document.ActiveWindow.ActivePane.View.SeekView := wdSeekCurrentPageHeader;
    InsertWordTextBox(WordApplication, 10, 10, 100, 100);
    WordApplication.Disconnect;
  finally
    WordApplication.free;
  end;
end;

luckystar85 30. Jan 2011 21:23

AW: Positionierung von Textbox in Worddokument über Delphi
 
Ich werde deinen Code einmal probieren, ob es mit den Änderungen funzt.

Ist bei dir auch der Rahmen um die TextBox weg? Das war ja auch ein Problem von mir. Trotz des Aufrufs von lTextBox.Fill.Visible := msoFalse; und lTextBox.Line.Visible := msoFalse; ist der bei 2003 noch da (s. Screenshot).

P.S.: Mein Aufruf InsertWordTextBox(WordApplication, 48.15, 9.35, 252, 61.25);

omata 30. Jan 2011 21:55

AW: Positionierung von Textbox in Worddokument über Delphi
 
Zitat:

Zitat von luckystar85 (Beitrag 1078391)
Ist bei dir auch der Rahmen um die TextBox weg?

Ja, bei Office 2000 ist der Rahmen nicht sichtbar.


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:39 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