Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
Delphi 7 Enterprise
|
AW: Positionierung von Textbox in Worddokument über Delphi
30. Jan 2011, 21: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;
|
|
Zitat
|