AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Delphi Positionierung von Textbox in Worddokument über Delphi
Thema durchsuchen
Ansicht
Themen-Optionen

Positionierung von Textbox in Worddokument über Delphi

Ein Thema von luckystar85 · begonnen am 29. Jan 2011 · letzter Beitrag vom 30. Jan 2011
Antwort Antwort
luckystar85

Registriert seit: 21. Dez 2004
Ort: Rostock
138 Beiträge
 
Delphi 2009 Professional
 
#1

Positionierung von Textbox in Worddokument über Delphi

  Alt 29. Jan 2011, 15:18
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;
Michael Klüber
Delphi ist was solides und besteht nicht wie C/C++ Quelltext nur aus Kommentaren.
  Mit Zitat antworten Zitat
omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#2

AW: Positionierung von Textbox in Worddokument über Delphi

  Alt 29. Jan 2011, 18:13
Hast du mal in Office 2003 die Textboxerstellung mit dem Makrorekorder aufgezeichnet? Gibt es da Unterschiede zu deinen bisherigen Befehlen und wenn ja welche?
  Mit Zitat antworten Zitat
Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#3

AW: Positionierung von Textbox in Worddokument über Delphi

  Alt 29. Jan 2011, 18:27
@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.
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat
luckystar85

Registriert seit: 21. Dez 2004
Ort: Rostock
138 Beiträge
 
Delphi 2009 Professional
 
#4

AW: Positionierung von Textbox in Worddokument über Delphi

  Alt 29. Jan 2011, 18:44
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.
Michael Klüber
Delphi ist was solides und besteht nicht wie C/C++ Quelltext nur aus Kommentaren.
  Mit Zitat antworten Zitat
Benutzerbild von sx2008
sx2008

Registriert seit: 15. Feb 2008
Ort: Baden-Württemberg
2.332 Beiträge
 
Delphi 2007 Professional
 
#5

AW: Positionierung von Textbox in Worddokument über Delphi

  Alt 29. Jan 2011, 19:11
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.
  Mit Zitat antworten Zitat
luckystar85

Registriert seit: 21. Dez 2004
Ort: Rostock
138 Beiträge
 
Delphi 2009 Professional
 
#6

AW: Positionierung von Textbox in Worddokument über Delphi

  Alt 29. Jan 2011, 20:05
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;
Miniaturansicht angehängter Grafiken
screenshot_2003.png   screenshot_2010.png  
Michael Klüber
Delphi ist was solides und besteht nicht wie C/C++ Quelltext nur aus Kommentaren.
  Mit Zitat antworten Zitat
omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#7

AW: Positionierung von Textbox in Worddokument über Delphi

  Alt 30. Jan 2011, 20:08
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;
  Mit Zitat antworten Zitat
luckystar85

Registriert seit: 21. Dez 2004
Ort: Rostock
138 Beiträge
 
Delphi 2009 Professional
 
#8

AW: Positionierung von Textbox in Worddokument über Delphi

  Alt 30. Jan 2011, 21:23
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);
Michael Klüber
Delphi ist was solides und besteht nicht wie C/C++ Quelltext nur aus Kommentaren.
  Mit Zitat antworten Zitat
omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#9

AW: Positionierung von Textbox in Worddokument über Delphi

  Alt 30. Jan 2011, 21:55
Ist bei dir auch der Rahmen um die TextBox weg?
Ja, bei Office 2000 ist der Rahmen nicht sichtbar.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:22 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