Escolar Documentos
Profissional Documentos
Cultura Documentos
Código
{
Exemplo de como gerar um arquivo em excel formatado e pronto para a
impressão.
Peço a todos que lerem esta dica e que tem algo a acrescentar, por
favor mande
para o email que segue abaixo.
Roberto
rcdslf@gmail.com
11/09/2008
}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses ComObj;
{$R *.dfm}
//cria a aplicação
Excel := CreateOleObject('Excel.Application');
//mostra a tabela
Excel.Visible := true;
//Repassando variável
Sheet := Excel.WorkBooks[1].WorkSheets[Nome];
(*--------------------------------------------------------------------
--------*)
(*--------------------------------------------------------------------
--------*)
(*--------------------------------------------------------------------
--------*)
//Mesclando Células
Sheet.Range['B2:D2'].MergeCells := true;
Sheet.Range['B4:D4'].MergeCells := true;
Sheet.Range['B6:D6'].MergeCells := true;
(*--------------------------------------------------------------------
--------*)
(*--------------------------------------------------------------------
--------*)
{Material}
Sheet.Range['B4'].Font.Name := 'Arial';
Sheet.Range['B4'].Font.Bold := true;
Sheet.Range['B4'].Font.Size := 16;
{Referência}
Sheet.Range['B6'].Font.Name := 'Arial';
Sheet.Range['B6'].Font.Bold := true;
Sheet.Range['B6'].Font.Size := 16;
{Itens}
Sheet.Range['B9:D9'].Font.Name := 'Arial';
Sheet.Range['B9:D9'].Font.Size := 14;
(*--------------------------------------------------------------------
--------*)
(*--------------------------------------------------------------------
--------*)
(*--------------------------------------------------------------------
--------*)
(*--------------------------------------------------------------------
--------*)
{
- Adicionar figura
Esta dica pode ser meio inconviniente pois ela não direciona um lugar
específico
para a colocação da imagem, mas nm por isso deixa de ser importante.
Sheet.Pictures.Insert('lugar_onde_se_encontra_a_figura');
- Adicionar um Replace
Serve como um find / replace, ele procura e substiui a string por
outra q deseja.
Ele subtitiu apenas o conteúdo q vc deseja o restante da string não
muda.
Sheet.Range['A1:Z70'].Replace('Tam.:', 'Num.:');
|| ||
Onde: local da pesquisa / ('Texto_Procurado', 'Subtituir_Por')
}
(*--------------------------------------------------------------------
--------*)
//Configuração da folha
Sheet.PageSetup.BottomMargin := 10;
Sheet.PageSetup.LeftMargin := 10;
Sheet.PageSetup.RightMArgin := 10;
Sheet.PageSetup.TopMargin := 10;
//Print Preview
Sheet.Range['A1:E10'].PrintPreview;
(*--------------------------------------------------------------------
--------*)
end;
end.