Форум: "Основная";
Текущий архив: 2004.03.05;
Скачать: [xml.tar.bz2];
ВнизОдновременная замена в WORD Найти похожие ветки
← →
Эли (2004-02-25 12:47) [2]unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComObj, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TWordReplaceFlags = set of (wrfReplaceAll, wrfMatchCase, wrfMatchWildcards);
var
Form1: TForm1;
implementation
{$R *.dfm}
function WordStringReplace(ADocument: TFileName; SearchString, ReplaceString: string; Flags: TWordReplaceFlags): Boolean;
const
wdFindContinue = 1;
wdReplaceOne = 1;
wdReplaceAll = 2;
wdDoNotSaveChanges = 0;
var
WordApp: OLEVariant;
begin
Result := False;
if not FileExists(ADocument) then
begin
ShowMessage("File is not found");
Exit;
end;
try
WordApp := CreateOLEObject("Word.Application");
except
on E: Exception do
begin
E.Message := "Word in not avaylable";
raise;
end;
end;
try
WordApp.Visible := False;
WordApp.Documents.Open(ADocument);
WordApp.Selection.Find.ClearFormatting;
WordApp.Selection.Find.Text := SearchString;
WordApp.Selection.Find.Replacement.Text := ReplaceString;
WordApp.Selection.Find.Forward := True;
WordApp.Selection.Find.Wrap := wdFindContinue;
WordApp.Selection.Find.Format := False;
WordApp.Selection.Find.MatchCase := wrfMatchCase in Flags;
WordApp.Selection.Find.MatchWholeWord := False;
WordApp.Selection.Find.MatchWildcards := wrfMatchWildcards in Flags;
WordApp.Selection.Find.MatchSoundsLike := False;
WordApp.Selection.Find.MatchAllWordForms := False;
if wrfReplaceAll in Flags then
WordApp.Selection.Find.Execute(Replace := wdReplaceAll)
else
WordApp.Selection.Find.Execute(Replace := wdReplaceOne);
WordApp.ActiveDocument.SaveAs(ADocument);
Result := True;
WordApp.ActiveDocument.Close(wdDoNotSaveChanges);
finally
WordApp.Quit;
WordApp := Unassigned;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WordStringReplace(Edit1.Text,Edit2.text,Edit3.Text, [wrfReplaceAll]);
end;
end.
Страницы: 1 вся ветка
Форум: "Основная";
Текущий архив: 2004.03.05;
Скачать: [xml.tar.bz2];
Память: 0.44 MB
Время: 0.01 c