Relatório em Excel com Progress - Usando varios Recursos simples
Autor: Alexandre Amorim | Publicado: 2011-12-09T06:28:00-08:00

Abaixo demonstro um exemplo de relatório em progress&nbsp;que gera arquivo em excel todo comentado, vejam que utilizo varios recursos interessantes como titulo, numero de pagina e outras dicas de formatação..... 


/* Cria as variaveis necessárias para o relatório */DEF VAR chExcelApplication AS COM-HANDLE NO-UNDO.
DEF VAR chWorkbook AS COM-HANDLE NO-UNDO.
DEF var chworksheet AS com-handle.
DEF VAR m-linha AS INTEGER NO-UNDO. /* Variável p/ contagem das linhas */
ASSIGN m-linha = 1.
CREATE "Excel.Application" chExcelApplication. /* Cria a Planilha */
ASSIGN chWorkbook = chExcelApplication:Workbooks:ADD("")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chworksheet=chexcelapplicAtion:sheets:item(1)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chworksheet:name="Pasta do Relatório". /* Nome que será criada a Pasta da Planilha */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m-linha = 2.
&nbsp;&nbsp;&nbsp; ASSIGN chWorkSheet:PageSetup:Orientation = 1. /* Define papel como formato Retrato */
&nbsp;&nbsp;&nbsp; ASSIGN chworksheet:range("A1:C1"):FONT:colorindex = 02 /* Aplica fonte cor Branca no Titulo */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chworksheet:range("A1:C1"):MergeCells = TRUE. /* Cria a Planilha */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chworksheet:range("A1:C1"):VALUE = "Titulo - Titulo do Relatório".
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chWorkSheet:Range("A1:C1"):HorizontalAlignment = 3. /* Centraliza o Titulo */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chWorkSheet:Range("A1:C1"):Interior:colorindex = 01. /* Aplica fundo preto no titulo */
&nbsp;&nbsp;&nbsp;&nbsp; /* Cria os titulos para as colunas do relatório */ 
&nbsp;&nbsp;&nbsp; ASSIGN chworksheet:range("A2:C2"):font:bold = TRUE&nbsp; /* Aplica negrito na linha de titulo das colunas */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chworksheet:range("A" + STRING(m-linha)):VALUE = "TituloColuna A"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chworksheet:range("B" + STRING(m-linha)):VALUE = "TituloColuna B"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chworksheet:range("C" + STRING(m-linha)):VALUE = "TituloColuna C"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m-linha = m-linha + 1. 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Faça o for each desejado */&nbsp;&nbsp;&nbsp; FOR EACH tabela NO-LOCK:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Lista os dados da tabela nas colunas */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ASSIGN chworksheet:range("A" + STRING(m-linha)):VALUE = tabela.campo1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chworksheet:range("B" + STRING(m-linha)):VALUE = tabela.campo2
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chworksheet:range("C" + STRING(m-linha)):VALUE = tabela.campo3.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ASSIGN m-linha = m-linha + 1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; END.
&nbsp;&nbsp;&nbsp; ASSIGN 
&nbsp;&nbsp;&nbsp; chExcelApplication:Range("B1:B65000"):NumberFormat = "dd/mm/aaaa"&nbsp; /* Formato de data na col B */
&nbsp;&nbsp;&nbsp; chExcelApplication:Range("C1:C65000"):NumberFormat = "#.##0,00". /* formato numerico c/2 dec na col C */
&nbsp;&nbsp;&nbsp; chWorkSheet:PageSetup:RightFooter&nbsp; = "&amp;d/&amp;t" + "-PAGINA:" + "&amp;P/&amp;N". /* Data/Hora e Nr Pg no Rodapé */
&nbsp;&nbsp;&nbsp; chworksheet:range("B2:C2"):EntireColumn:AutoFit. /* Define automaticamente a largura das colunas */
&nbsp;&nbsp;&nbsp; chExcelApplication:COLUMNS("A:A"):ColumnWidth = 25.00. /* Define manualmente a largura da coluna A */
&nbsp;&nbsp;&nbsp; chExcelApplication:Rows("1:65000"):RowHeight&nbsp; = 17.00. /* Tamanho da linha */
&nbsp;&nbsp;&nbsp; chWorkSheet:PageSetup:PrintTitleRows&nbsp; = "$1:$1". /* Adiciona o Titulo em todas as paginas de Impressao */
&nbsp;&nbsp;&nbsp; chWorkSheet:PageSetup:Zoom&nbsp; = 80. /* Aplica 80% para ajuste na impressao da pagina */
&nbsp;&nbsp;&nbsp; chExcelApplication:Range("A1"):select.
&nbsp;&nbsp;&nbsp; chExcelApplication:Visible = yes. 
&nbsp;&nbsp;&nbsp; RELEASE OBJECT chExcelApplication.
&nbsp;&nbsp;&nbsp; RELEASE OBJECT chWorkbook.