![]() |
Replace string in *.docx
Liste der Anhänge anzeigen (Anzahl: 1)
Hi all,
I need to change the text in the text box. This procedure changes only plain text.
Delphi-Quellcode:
WordApp.Selection.Find. ????????????????????? TextBox ???????
function Word_StringReplace(ADocument: TFileName; Ss, Rs: string; Flags: TWordReplaceFlags): Boolean;
const wdFindContinue = 1; wdReplaceOne = 1; wdReplaceAll = 2; wdDoNotSaveChanges = 0; var WordApp: OLEVariant; begin Result := False; { Check if file exists } if not FileExists(ADocument) then begin ShowMessage('Specified Document not found.'); Exit; end; { Create the OLE Object } try WordApp := CreateOLEObject('Word.Application'); except on E: Exception do begin E.Message := 'Word is not available.'; raise; end; end; try { Hide Word } WordApp.Visible := False; { Open the document } WordApp.Documents.Open(ADocument); { Initialize parameters} WordApp.Selection.Find.ClearFormatting; WordApp.Selection.Find.Text := Ss; WordApp.Selection.Find.Replacement.Text := Rs; WordApp.Selection.Find.Forward := True; WordApp.Selection.Find.Wrap := wdFindContinue; WordApp.Selection.Find.Format := True; WordApp.Selection.Find.MatchCase := wrfMatchCase in Flags; WordApp.Selection.Find.MatchWholeWord := True; WordApp.Selection.Find.MatchWildcards := wrfMatchWildcards in Flags; WordApp.Selection.Find.MatchSoundsLike := False; WordApp.Selection.Find.MatchAllWordForms := False;
Delphi-Quellcode:
Example
{ Perform the search}
if wrfReplaceAll in Flags then WordApp.Selection.Find.Execute(Replace := wdReplaceAll) else WordApp.Selection.Find.Execute(Replace := wdReplaceOne); { Save word } WordApp.ActiveDocument.SaveAs(ADocument); { Assume that successful } Result := True; { Close the document } WordApp.ActiveDocument.Close(wdDoNotSaveChanges); finally { Quit Word } WordApp.Quit; WordApp := Unassigned; end; end; Word_StringReplace('mydoc.docx','<fname_lname>','M y Name',[wrfReplaceAll]); |
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:35 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz