Fill in a Word document from Delphi

6

I want to create a system in Delphi , where I fill in the labels and after creating a document in word with the information that I typed ...

I put an example below where I'm going to enter the information and when I generate it it will throw this information into a Word document

    
asked by anonymous 16.05.2014 / 02:11

2 answers

6

One of the easiest ways to integrate Delphi with Word is through OleObject , but keep in mind that if the machine running the application, if Word is not installed , will generate a EOleException of Class not registered.

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 in order to do this your document should be as follows, and remembering to put the name of the objects TEdit to yours in your form:

|Nome   |   Sobrenome   |   Endereco    |  Telefone    |  
--------------------------------------------------------  
|[Nome] |   [Sobrenome] |   [Endereco]  |  [Telefone]  |  
    
16.05.2014 / 03:41
1

A simple way would also be to generate the PDF relationship, through a quickreport for example and install a virtual printer, which when "print" saved in word doc.

    
16.05.2014 / 17:05