One of the easiest ways to integrate Delphi
with the Word
is through a OleObject
, but keep in mind that if on the machine that will run the application, if the Word
not installed, will generate a EOleException
unregistered.
function PreencherDadosArquivo(const NomeArquivo: string): Boolean;
var
WordApp: Variant;
Documento: Olevariant;
begin
WordApp:= CreateOleObject('Word.Application');
try
WordApp.Visible := False;
Documento := WordApp.Documents.Open(NomeArquivo);
Documento.Content.Find.Execute(FindText := '[Nome]', ReplaceWith := edtNome.Text);
Documento.Content.Find.Execute(FindText := '[Sobrenome]', ReplaceWith := edtSobreNome.Text);
Documento.Content.Find.Execute(FindText := '[Endereco]', ReplaceWith := edtEnd.Text);
Documento.Content.Find.Execute(FindText := '[Telefone]', ReplaceWith := edtTel.Text);
Documento.SaveAs('SeuNovoNomeArquivo.doc')
finally
WordApp.Quit;
end;
end;
But to do so your document should be as follows, and remembering to put the name of the objects TEdit
for your form:
|Nome | Sobrenome | Endereco | Telefone |
--------------------------------------------------------
|[Nome] | [Sobrenome] | [Endereco] | [Telefone] |
Note to the "veterans" of the site: I even agree that the question is in need of an improvement, and details, but the people who vote to close could be a little less hasty, and spend more time guiding than voting. If it doesn’t work, then it’s okay.
– Bacco
@user8626 : Welcome to Sopt. I suggest you read this link to improve your question: http://answall.com/help/how-to-ask . After a read, you can click "edit" just below your question to add more details.
– Bacco
Good morning Anderson. If @Caputo’s reply answers your question I ask you to please accept it so that it does not appear unanswered. If not, please provide more details than you really want so that a response can come.
– Filipe.Fonseca