Olá galera, nesta Quick Tips, irei mostra como podemos incluir um cabeçalho e rodapé num documento do Microsoft Word, usando o Delphi.
Vamos adicionar certos componentes agora:
1 BitBtn ( BtnVisualizar )
5 Edits ( EdtTexto1, EdtTexto2, EdtTexto3, EdtTexto4, EdtTexto5)
1 Combobox(CbxMensagem)
2 RadioGroup (RdgAlinhamento, RdgSite)
2 Memo( MmCabecalho, MmRodape)
Veja o exemplo construído :
Agora vamos a implementação do BtnVisualizar:
procedure TFrmPrincipal.BtnVisualizarClick(Sender: TObject);
var
Word: OLEVariant;
begin
try
Word := CreateOleObject('Word.Application');
except
ShowMessage('Word não pode ser aberto');
Exit;
end;
// Exibe o Word
Word.Visible := True;
// Inclui um novo documento
Word.Documents.Add;
if Word.ActiveWindow.View.SplitSpecial <> 0 then
Word.ActiveWindow.Panes[2].Close;
if (Word.ActiveWindow.ActivePane.View.type = 1) or
(Word.ActiveWindow.ActivePane.View.type = 2) or
(Word.ActiveWindow.ActivePane.View.type = 5) then
Word.ActiveWindow.ActivePane.View.type := 3;
Word.ActiveWindow.ActivePane.View.SeekView := 9;
Word.Selection.Font.Name := 'Times New Roman';
Word.Selection.Font.Size := 12;
Word.Selection.Font.Bold := True;
Word.Selection.ParagraphFormat.Alignment :=
StrToInt(RdgAlinhamento.Items.Strings[RdgAlinhamento.ItemIndeItemIndex]);
Word.Selection.TypeText(Text := MmCabecalho.Text);
if Word.Selection.HeaderFooter.IsHeader = True then
Word.ActiveWindow.ActivePane.View.SeekView := 10
else
Word.ActiveWindow.ActivePane.View.SeekView := 9;
Word.Selection.TypeText(Text := MmRodape.Text);
Word.ActiveWindow.ActivePane.View.SeekView := 0;
Word.Selection.TypeText(Text := EdtTexto1.Text + ' ' + EdtTexto2.Text);
Word.Selection.TypeParagraph;
Word.Selection.TypeText(Text := EdtTexto3.Text);
Word.Selection.TypeParagraph;
Word.Selection.TypeParagraph;
Word.Selection.Font.Name := 'Times New Roman';
Word.Selection.Font.Size := 12;
Word.Selection.Font.Bold := True;
Word.Selection.TypeText(Text := EdtTexto4.Text + ' ' + EdtTexto5.Text);
Word.Selection.TypeParagraph;
Word.Selection.TypeParagraph;
Word.Selection.TypeParagraph;
Word.Selection.TypeParagraph;
Word.Selection.Font.Name := 'Arial';
Word.Selection.Font.Size := 14;
Word.Selection.Font.Bold := True;
Word.Selection.TypeText(Text := CbxMensagem.Text);
Word.Selection.TypeParagraph;
Word.Selection.TypeParagraph;
Word.Selection.TypeParagraph;
Word.Selection.TypeParagraph;
Word.Selection.TypeParagraph;
Word.Selection.Font.Name := 'Times New Roman';
Word.Selection.Font.Size := 12;
Word.Selection.Font.Bold := True;
if RdgSite.ItemIndex = 0 then
Word.Selection.TypeText(Text := 'DevMedia - ' +
RdgSite.Items.Strings[RdgSite.ItemIndex])
else
Word.Selection.TypeText(Text := 'Wesley Yamazack - ' +
RdgSite.Items.Strings[RdgSite.ItemIndex]);
end;
Fico por aqui ate à próxima Quick Tips. Baixe o exemplo completo neste post.
Um abraço
Wesley Y
wyamazack@rwsolution.com.br