Exportar relatório p/ excel
Enviado: 28 Mai 2008 11:43
Caros colegas, alguem poderia me dar uma dica de como exportar relatórios para o excel??
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 : ? )
Temos varios exemplos que pode depender de cada cituação.TerraSoftware escreveu:Caros colegas, alguem poderia me dar uma dica de como exportar relatórios para o excel??
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
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
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