Página 1 de 1

Exportar relatório p/ excel

Enviado: 28 Mai 2008 11:43
por TerraSoftware
Caros colegas, alguem poderia me dar uma dica de como exportar relatórios para o excel??

Re: Exportar relatório p/ excel

Enviado: 28 Mai 2008 15:26
por gvc
Vc pode importar os dados de um arquivo delimitado.
Pode usar a função postada pelo mestre Rochinha em https://pctoledo.org/forum/viewto ... =13&t=3223

Tem tb como fazer isso gerando o arquivo em HTML, mas gravando a extensão XLS. O Excell importa e transforma direto para o formato interno dele. Se eu não me engano, foi apresentado pelo mestre Rochinha tb.
Acredito que esteja aqui no forum, mas eu ainda não encontrei ainda.

Achei
Amiguinhos

Vejam uma forma de gerar arquivo XLS de forma rapida.

Basta usar o esquema de HTML e jogar a lista de dados para o Excel se virar.

Exemplo:
Código:

<html>
<body>
<table border="1">
<!-- cabecalho com os nomes dos campos da tabela -->
<tr>
<th nowrap>Time</th>
<th nowrap>Pontos</th>
<th nowrap>Jogos</th>
<th nowrap>Vitorias</th>
<th nowrap>Empates</th>
<th nowrap>Derrotas</th>
</tr>
<!-- cada registro da tabela deve estar dentro das tags TR -->
<tr>
<td align="right">Corinthians</td>
<td align="right">12</td>
<td align="right">8</td>
<td align="right">3</td>
<td align="right">2</td>
<td align="right">1</td>
</tr>
<tr>
<td align="right">Sao Paulo</td>
<td align="right">16</td>
<td align="right">4</td>
<td align="right">7</td>
<td align="right">6</td>
<td align="right">3</td>
</tr>
<tr>
<td align="right">Santos</td>
<td align="right">10</td>
<td align="right">9</td>
<td align="right">4</td>
<td align="right">3</td>
<td align="right">6</td>
</tr>
<tr>
<td align="right">Palmeiras</td>
<td align="right">12</td>
<td align="right">5</td>
<td align="right">3</td>
<td align="right">2</td>
<td align="right">1</td>
</tr>
</table>
</body>
</html>



Basta gerar o conteudo como o exemplo acima e salvar com extensão XLS.

@braços : ? )

Re: Exportar relatório p/ excel

Enviado: 28 Mai 2008 20:40
por sygecom
TerraSoftware escreveu:Caros colegas, alguem poderia me dar uma dica de como exportar relatórios para o excel??
Temos varios exemplos que pode depender de cada cituação.

1º Exemplo postado pelo Nosso colega Luciano Bomfim, que pode ser usado com TBROWSE()

Código: Selecionar todos

*********************
Function TB2Excel(oTB)  // gera excel para console a partir do tbrowse
*********************
local oExcel := CREATEOBJECT( "Excel.Application" )
local oSheet
local i,linha

oExcel:WorkBooks:Add()
oSheet = oExcel:ActiveSheet

for i := 1 TO oTB:ColCount
   oCol := oTB:GetColumn(i)
   cCell := oCol:Heading
   oSheet:Cells( 1, i ):Value = cCell
next

Eval (oTB:goTopBlock) // start from the top
linha=2
do while .t.
   for i := 1 TO oTB:ColCount
      oCol := oTB:GetColumn(i)
      uColData := Eval(oCol:Block) // column data (of yet unknown type)
      do case
      case ValType(uColData) == "C" // characters
         if ! Empty(oCol:picture)
            cCell := Transform (alltrim(uColData), oCol:picture)
         else
            cCell := alltrim(uColData)
         endif
         cCell="'"+cCell
      case ValType(uColData) == "N" // numbers
         cCell := uColData
      case ValType(uColData) == "L" // logicals
         cCell := if (uColData, "Sim", "Näo")
      case ValType(uColData) == "D" // dates
         cCell := uColData
      otherwise
         cCell := "error"
      endcase
      oSheet:Cells( linha, i ):Value = cCell
   next

   nTemp := Eval (oTB:SkipBlock, 1)
   if nTemp != 1
      exit
   endif
   linha++
enddo
Eval (oTB:goTopBlock)

oSheet:Rows( "1:1" ):Font:bold:=.t.
oSheet:Columns:AutoFit()

oExcel:Visible := .t.
return NIL
Em anexo um exemplo de uso dessa função do Luciano.

Peguei como exemplo o do Luciano e fiz um para Hwgui, segue abaixo a rotina para usar com Browse da Hwgui.

Código: Selecionar todos

***********************
Function Gera_Excel(oTB)
***********************
local oSheet
local i,linha
Local cText := ""
LOCAL nRecord := 0, nCount := 0

PRIVATE oDlgHabla:=NIL
MsgRun("Aguarde Gerando Documento EXCEL...")

TRY
   oExcel := GetActiveObject( "Excel.Application" )
CATCH
   TRY
      oExcel := CreateObject( "Excel.Application" )
   CATCH
      MSGINFO( "ERROR! Excel não esta Ativado. [" + Ole2TxtError()+ "]" )
      Fim_Run()
      RETURN
   END
END

oExcel:WorkBooks:Add()
oSheet = oExcel:ActiveSheet

for i := 1 TO Len(oTB:aColumns)
   cCell  := oTB:aColumns[i]:heading
   oSheet:Cells( 1, i ):Value = cCell
next

Eval (oTB:bGoTop) // start from the top
linha=2

WHILE ! EOF() .AND. EVAL(oBrw:bWhile)
   for i := 1 TO Len(oTB:aColumns)
      oCol := oTB:aColumns[i]:block
      uColData := Eval(oCol)

      do case
      case ValType(uColData) == "C" // characters
         if ! Empty(oTB:aColumns[i]:picture)
            cCell := Transform (alltrim(uColData), oTB:aColumns[i]:picture)
         else
            cCell := alltrim(uColData)
         endif
         cCell="'"+cCell
      case ValType(uColData) == "N" // numbers
         cCell := uColData
      case ValType(uColData) == "L" // logicals
         cCell := if (uColData, "Sim", "Nao")
      case ValType(uColData) == "D" // dates
         cCell := uColData
      otherwise
         cCell := "error"
      endcase
      oSheet:Cells( linha, i ):Value = cCell
   next

   IF EVAL(oBrw:bFor)
     nCount++
   ENDIF
   linha++
   DBSKIP()
ENDDO

Eval (oTB:bGoTop)

oSheet:Rows( "1:1" ):Font:bold:=.t.
oSheet:Columns:AutoFit()

Fim_Run()

oExcel:Visible := .t.

return NIL


Re: Exportar relatório p/ excel

Enviado: 28 Mai 2008 20:41
por sygecom
Em anexo exemplo de uso do Excel na Hwgui:

Re: Exportar relatório p/ excel

Enviado: 29 Mai 2008 12:02
por gvc
Peguei do FW Espanha e não testei.

Código: Selecionar todos

FUNCTION MAIN()

    LOCAL oExcel := CREATEOBJECT( "Excel.Application" )

    LOCAL oSheet

    oExcel:WorkBooks:Open( "E:\XHARBOUR\TEST.XLS" )

    oSheet = oExcel:ActiveSheet

    ? oSheet:Cells( 1, 1 ):Value
    ? oSheet:Cells( 2, 1 ):Value
    ? oSheet:Cells( 3, 1 ):Value

    ? oSheet:Range( "A1" ):Value

    oExcel:Quit()

    RETURN NIL

Re: Exportar relatório p/ excel

Enviado: 29 Mai 2008 15:22
por rodrmigu
Olá,

Tenho usado até hoje através de OLE e tem servido bem, é um pouco lento, mas se nota apenas com grandes relatorios convertidos pra excel, as vezes da um bugzinho e nao consegue criar a planilha. Mas essa de se gerar em .html e salvar como .xls foi muito boa, já testei aqui e funciona bem!

[]'s
Rodrigo