I'll explain by following the rationale logic as if we were developing from scratch an impression in Word.
First: Have a report template in Word, perhaps putting it as a resource
of the application will ensure better security to prevent it from being changed by a third party (as if it were a static file).
Second: Use variables of type variant
to instantiate the Word object, it would look something like this:
uses Word2000, ComObj;
function CriarObjetoWord(out pObjWord: variant): boolean;
begin
Result := False;
try
pObjWord := CreateOleObject('Word.Application');
Result := True;
except
ShowMessage('Erro ao criar objeto Word');
end;
end;
Third: You will need to define in your report which fields will be changed, as you said yourself, you will need to change teacher, date, name of training, etc. In the document, place an identifier in the report for the text to be replaced, for example:
Eu, @nomeprofessor, atesto que estou realizando o curso de @nomedocurso na data @data.
Room: Once you have the template ready, just change and / or add the fields as follows:
procedure PreencherRelatorio;
var
vObjWord: variant;
i, vQtd: integer;
begin
if not CriarObjetoWord(vObjWord) then
Exit;
{ para substituir campos }
vObjWord.Content.Find.Execute(FindText := ´@nomeprofessor´, ReplaceWith := 'Lucas de Souza');
vObjWord.Content.Find.Execute(FindText := ´@nomedocurso ´, ReplaceWith := 'Lógica de Programação');
vObjWord.Content.Find.Execute(FindText := ´@data´, ReplaceWith := '21/12/2017');
{ vai pra última linha }
vObjWord.Selection.EndKey(wdStory);
{ para adicionar linhas }
vQtd := vObjWord.ActiveDocument.Bookmarks.Count;
for i := 0 to 10 do
begin
vObjWord.ActiveDocument.Bookmarks.Add(Name := 'Teste');
vObjWord.ActiveDocument.Bookmarks.Item(vQtd + 1).Range.Text := 'Olá: ' + IntToStr(i) + #13;
end;
end;
This solved my problem, I hope it solves your problem.