visualizar relatórios em html...

Projeto [x]Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

Avatar do usuário
FARLEY RIBEIRO
Usuário Nível 2
Usuário Nível 2
Mensagens: 89
Registrado em: 24 Jul 2007 10:26
Localização: MONTES CLAROS-MG

visualizar relatórios em html...

Mensagem por FARLEY RIBEIRO »

olá pessoal,

hoje gero meus arquivos em txt ou em dbf e os visualizo na tela...
(tbrowse)..
gostaria que os mesmos fossem gerados em html e pudesse-los visualizá-los
através do browser (internet,firefox,etc).

alguém tem alguma idéia?

abraços

farley
Borland BCC(5.51)/PellesC(5.01)/Fivewin(2.6)/xHarbour.org(0.99.50)/Med(3.02)/DBFNTX/DBFCDX /WvWToools(0.83)
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Re: visualizar relatórios em html...

Mensagem por Itamar M. Lins Jr. »

FARLEY RIBEIRO escreveu:olá pessoal,

hoje gero meus arquivos em txt ou em dbf e os visualizo na tela...
(tbrowse)..
gostaria que os mesmos fossem gerados em html e pudesse-los visualizá-los
através do browser (internet,firefox,etc).

alguém tem alguma idéia?

abraços

farley
Ola!

Segue exemplo em HWGUI.
Mas de fácil conversão para outras GUI.

Saudações
Itamar M. Lins Jr.

Código: Selecionar todos

**********************
Function RelReceber003
**********************
*
*
Local oDprint,oFont, aOrdem := {'Alfabetica','Pagamento'}
Local oInicio,oFim, lOk := .f., vOrdem := ''
private inicio := fim := ctod(''), vFv01 := 1
vCli := spac(len(re->cod_client))

PREPARE FONT oFont NAME "MS Sans Serif" WIDTH 0 HEIGHT -10

INIT DIALOG oDPrint CLIPPER NOEXIT TITLE "Contas Recebidas" Font oFont AT 0,0 SIZE 350,180 ;
                                                       STYLE  WS_POPUP+WS_VISIBLE+WS_CAPTION+WS_SYSMENU+DS_CENTER

 @ 005,020 say "Data Inicial:" SIZE 260,22
 @ 075,015 get oInicio var inicio size 60,20 valid {||!empty(inicio)}

 @ 005,050 say "Data Final..:" SIZE 260,22
 @ 075,045 get oFim var fim  size 60,20  valid {||!empty(fim)}

 @ 005,080 say "Finalizadora:" SIZE 260,22
 @ 075,075 get ComboBox oFv01 Var vFv01 ITEMS aFormVend[1] Size 180,150

 @ 005,110 say "Cliente:" SIZE 260,22
 @ 075,105 get oCli var vCli size 60,20

 @ 005,140 say 'Ordem:' size 70,20
 @ 075,135 get ComboBox oOrdem Var vOrdem ITEMS aOrdem TEXT size 100,060

 @ 250,012 Button oBt Caption 'Cancelar'   Size 70,30  ON CLICK {||EndDialog()}
 @ 250,110 Button oBt Caption 'Confirmar'  Size 70,30  ON CLICK {||lOk:=.t.,EndDialog()}

oDPrint:Activate()

if lOk
else
   return .t.
endif

if vFv01 > 1
  fv->(DbGoto(aFormVend[2,vFv01]))
  vFv01 := fv->cod_venda
else
  vFv01 := ''
endif
 
//rodape('Deixe Vazio Para Todos os Clientes e Todas as Finalizadoras')

if !empty(vFv01)
  vFv01 := alltrim(vFv01)
endif
if !empty(vCli)
   vCli := alltrim(vCli)
endif

cArq := CriaArqImpressao('Recebidos.html')
stor 0 to tot_a,tot_b

if substr(vOrdem,1,1) = 'A'
 re->(OrdSetFocus(3))
else
  re->(OrdSetFocus(9))
endif

re->(dbgotop())

?  '<html><head>'
?? '<meta http-equiv = "Content-Type" content="text/html; '
?? 'charset=iso-8859-1">'
?  '<title>Contas Recebidas</title>'
?  '<style>'
?  'p.quebra { page-break-before: always }'
?  '</style></head>'
?? '<div align="center">'

CabRec003()

Do While !re->(eof())

   if empty(re->pagamento)
      re->(dbskip())
      loop
   endif
   
   if empty(vFv01)
   else
    if re->cod_venda = vFv01
    else
      re->(dbskip())
      loop
    endif
   endif
   
   if re->pagamento >= inicio .and. re->pagamento <= fim
   else
      re->(dbskip())
      loop
   endif
     
     if empty(vCli)
     else
       if len(vCli) = 2
         if substr(re->cod_client,1,2) = vCli
         else
          re->(dbskip())
          loop
         endif
       else
         if re->cod_client = vCli
         else
           re->(dbskip())
           loop
         endif
           //?  '<tr bgcolor="#FF0101">'
           //?  '<td clspan=6> Cliente: '+cl->cliente+'</tr>'
         //linha++
       endif
     endif
      
     ?  '<tr bgcolor="#FFFFFF">'
     ?? '<td><font size=2>'+re->cod_venda
     ?? '<td><font size=2>'+re->cod_client
     ?? '<td><font size=2>'+re->cliente
     ?? '<td>'+dtoc(re->pagamento)
     ?? '<td>'+dtoc(re->vencimento)
     ?? '<td align=right>'+transf(re->valor    ,'@e 9,999,999.99')
     ?? '<td align=right>'+transf(re->acrescimo,'@e 9,999,999.99')
     
     tot_a += re->valor
     tot_b += re->acrescimo
     re->(dbskip())

enddo
?  '<tr bgcolor="#FFFFFF">'
?? '<td colspan=5>Total do Período:'
?? '<td align=right>'+transf(tot_a,'@e 9,999,999.99')
?? '<td align=right>'+transf(tot_b,'@e 9,999,999.99')+'</tr>'
?  '</table></html>'

FecharImpres()

re->(dbgotop())
ShellExecute(cArq,"open",nil,cPasta,1)

Avatar do usuário
Luciano Bonfim
Usuário Nível 3
Usuário Nível 3
Mensagens: 414
Registrado em: 23 Ago 2007 09:34
Localização: Rio de Janeiro / São Paulo
Contato:

Mensagem por Luciano Bonfim »

se está no Tbrowse fica moleza, pega essas duas funçöes ai que manda do tbrowse para HTML e do tbrowse para XML

Código: Selecionar todos


function TB2Html (oTB, cHtmlFile, cTitle)
static cSetClrBg := "#ffffff" // background color
static cSetClrTab := "#c0c0c0" // table background
static cSetClrText := "#0000ff" // text color (for table and header text)
static cSetBgImage := "" // background image (.GIF picture)
static cSetTbImage := "" // background image (.GIF picture)
local xHtml, i, oCol, nTemp
local uColData, cAlign, cCell

aviso("Gerando arquivo HTML")

if ValType(oTB) != "O"
   return .f.
endif
if Empty(cHtmlFile)
   cHtmlFile := "TB2HTML.htm"
endif

xHtml := FCreate (cHtmlFile, FC_NORMAL)
if FError() != 0
   return .f.
endif

// HTML header
FWrite (xHtml, '<HTML>' + CRLF)
FWrite (xHtml, '<HEAD>' + CRLF)
FWrite (xHtml, ' <TITLE>' + cTitle + '</TITLE>' + CRLF)
FWrite (xHtml, ' <meta name="Author" CONTENT="">' + CRLF)
FWrite (xHtml, ' <meta name="GENERATOR" CONTENT="' + ;
 'Bonfim Sistemas Ltda.">' + CRLF)
FWrite (xHtml, "</HEAD>" + CRLF)

// setting colors - note than we are setting only background (BGCOLOR)
// and text (TEXT) color, not the link colors (LINK/VLINK/ALINK)
FWrite (xHtml, '<BODY BGCOLOR="'+ cSetClrBg + '"')
FWrite (xHtml, ' TEXT="' + cSetClrText + '"')
if ! Empty(cSetBgImage)
   FWrite (xHtml, ' background="' + cSetBgImage + '"')
endif
FWrite (xHtml, '>' + CRLF)

// all centered (including table) from here
FWrite (xHtml, '<CENTER>' + CRLF)

// define table display format (border and cell look)
// and structure (number of columns)
FWrite (xHtml, '<TABLE ') // don't delete space chars from end
FWrite (xHtml, 'BGCOLOR="'+ cSetClrTab + '" ')
if ! Empty(cSetTbImage)
   FWrite (xHtml, ' background="' + cSetTbImage + '"')
endif
FWrite (xHtml, 'BORDER=1 ')
FWrite (xHtml, 'FRAME=ALL ')
FWrite (xHtml, 'CellPadding=2 ')
FWrite (xHtml, 'CellSpacing=2 ')
FWrite (xHtml, 'COLS=' + AllTrim(Str(oTB:ColCount)))
FWrite (xHtml, '>'+CRLF)

// write table title (in bold face)
if ! Empty(cTitle)
   FWrite (xHtml, '<CAPTION ALIGN=TOP><B>' + cTitle + '</B></CAPTION>')
   FWrite (xHtml, CRLF)
endif

// output column headers
FWrite (xHtml, "<TR>" + CRLF)
for i := 1 TO oTB:ColCount
   oCol := oTB:GetColumn(i)
   cCell := oCol:Heading
   cCell := StrTran(cCell, ";", "<BR>")
   FWrite (xHtml, " <TH COLSPAN=1 VALIGN=BOTTOM>" + cCell + CRLF)
next
FWrite (xHtml, "</TR>" + CRLF)
FWrite (xHtml, CRLF)

// here comes the main loop which generate the table body
FWrite (xHtml, '<TBODY>' + CRLF)
Eval (oTB:goTopBlock) // start from the top

do while .t.
   FWrite (xHtml, "<TR>") // new table row

   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(uColData)
            cCell := "&nbsp"
         else
            if ! Empty(oCol:picture)
               cCell := Transform (alltrim(uColData), oCol:picture)
            else
               cCell := Str(uColData)
            endif
         endif
         cAlign := "<TD Align=Left>"
         
      case ValType(uColData) == "N" // numbers
         if ! Empty(oCol:picture)
            cCell := Transform (uColData, oCol:picture)
         else
            cCell := Str(uColData)
         endif
         if Empty(cCell)
            cCell := "&nbsp" // non-breaking space
         endif
         cAlign := "<TD Align=Right>"
         
      case ValType(uColData) == "L" // logicals
         cCell := if (uColData, "Sim", "Näo")
         cAlign := "<TD ALIGN=CENTER>"
         
      case ValType(uColData) == "D" // dates
         if Empty(uColData) // empty dates
            cCell := "&nbsp"
         else
            cCell := DToC(uColData)
         endif
         cAlign := "<TD ALIGN=CENTER>"
         
      otherwise
         cCell := "error"
         cAlign := "<TD ALIGN=CENTER>"
      endcase
      FWrite (xHtml, cAlign + cCell)
   next

   FWrite (xHtml, "</TR>" + CRLF) // end of row

   nTemp := Eval (oTB:SkipBlock, 1)
   if nTemp != 1 // it's the end, so we are getting out
      exit
   endif
enddo // main loop

Eval (oTB:goTopBlock) // set TBrowse back to top

// writing HTML tail
FWriteLn (xHtml, "</TBODY>" )
FWriteLn (xHtml, "</TABLE>" )
FWriteLn (xHtml, "</CENTER>")
FWriteLn (xHtml, "</BODY>" )
FWriteLn (xHtml, "</HTML>" )
FClose(xHtml)

apagaAviso()

abreIE(curdrive()+":\"+rtrim(curdir()) + "\"+cHtmlFile)
return .t.


function TB2Excel(oTB)
local oExcel := CREATEOBJECT( "Excel.Application" )
local oSheet
local i,linha

aviso("Gerando arquivo XLS")

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

//oSheet:Cells:Font:Name := "Arial"
//oSheet:Cells:Font:Size := 9

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()

//oSheet:Rows( "1:2" ):Delete()
//oSheet:Columns( "A:B" ):AutoFit()

oExcel:Visible := .t.

//oSheet:SaveAs( "c:\clientes\gopec\gop32\gop\SAVED.XLS" )
//oExcel:Quit()
apagaAviso()
return NIL




Muito Obrigado,

Luciano Bonfim de Azevedo
www.bonfim.com.br
luciano@bonfim.com.br
www.linkedin.com/in/lucianobonfim
Skype : lucianobonfim
Avatar do usuário
gvc
Colaborador
Colaborador
Mensagens: 1270
Registrado em: 23 Ago 2005 10:57

Mensagem por gvc »

Monte um modelo em HTML de como seu relatório deve ser.
Pegue o texto HTML e determine quais as partes fixas e as variáveis.
Como o HTML é um arquivo texto, vc tem que abrir o arquivo, gravar o texto, respeitando as regras do HTML e esta pronto.
Vc pode usar:
- set printer to
- set alternate to
- fwrite
"TRS-80/Sincler/Apple/PC - Clipper Winter 85, tlink 1.0 [pc 10 MHz - 640K] {NEZ 8000 2Kb RAM}"
{POG - Programação Orientada a Gambiarra}
toya
Usuário Nível 3
Usuário Nível 3
Mensagens: 157
Registrado em: 26 Jul 2004 16:51
Localização: Campo Grande/MS - Brasil
Contato:

Html...

Mensagem por toya »

Te envie um modelo via e-mail...
Se não recebestes me avise...
Elcio Carlos
(toya)
Ahora en la version 6.5
toyasis@gmail.com (e-mail)
toyaskype (skype)
http://www.toyanet.com.br
https://www.facebook.com/profile.php?id=100009195956044

FWH 11.8+PellesC+xHarbour.org 1.2.1+SqlRDD
Clippeiro por opção, Fivewiner por amor ao Clipper...
2015 - Iniciante/Aprendiz de HMG...
cl@udio
Usuário Nível 2
Usuário Nível 2
Mensagens: 88
Registrado em: 25 Jan 2007 16:47

Mensagem por cl@udio »

ericmagaldi
Porque voce não posta aqui na seção de codigo fonte.
Ai não vamos precisar ir para outro forum.
[]s
claudio
Avatar do usuário
sygecom
Administrador
Administrador
Mensagens: 7131
Registrado em: 21 Jul 2006 10:12
Localização: Alvorada-RS
Contato:

Mensagem por sygecom »

cl@udio escreveu:ericmagaldi
Porque voce não posta aqui na seção de codigo fonte.
Ai não vamos precisar ir para outro forum.
[]s
claudio
Olá Claudio,
O exemplo que o Eric se refere ele pegou da pasta "\xharbour\tests\tiptest" se vc tem o xharbour da CVS ai é só ir na pasta que indiquei e compilar o exemplo "dbToHtml.prg" se alguem quiser posso postar aqui.

Abraços
Leonardo Machado
Leonardo Machado
xHarbour.org + Hwgui + PostgreSql
Responder