Pra gerar direto no EXCEL podendo escolher a versão do Excel teria q fazer tipo o exemplo abaixo:
Código: Selecionar todos
IF (oExcel := Cria_OLE("Excel.Application", "Erro! O Excel n„o esta Ativado ou N„o instalada nesse Computador", .T.) ) == NIL
RETURN
ENDIF
oExcel:WorkBooks:Add()
oSheet := oExcel:ActiveSheet
oSheet:Name := 'Analise Geral'
oSheet:Cells( 1, 1 ):Value := "Codigo"
oSheet:Cells( 1, 2 ):Value := "Descricao"
oSheet:Cells( 1, 3 ):Value := "Qtde"
oSheet:Cells( 1, 4 ):Value := "Estq Atual"
oSheet:Cells( 1, 5 ):Value := "Vlr. Medio"
oSheet:Cells( 1, 6 ):Value := "Vlr. Total"
FOR i=1 to 6
oSheet:Cells( 1, i ):Font:Bold := .T.
oSheet:Cells( 1, i ):Font:ColorIndex := 2 //-- Cor da letra
oSheet:Cells( 1, i ):Interior:ColorIndex := 11 //-- Cor de Fundo
oSheet:Cells( 1, i ):HorizontalAlignment := -4108 // Alinhamento Centro
oSheet:Columns(i):ColumnWidth := 15 // Tamanho da Coluna
NEXT
oSheet:Columns(2):ColumnWidth := 40 // Tamanho da Coluna
oSheet:Cells( 1, 1 ):Select()
oExcel:Visible := .F.
nLinPlan := 2
xTotalEstq := xTotalCust := xTotalVend := 0
WHILE TMP_ITENS->(!EOF())
Mostra("Gerando..."+ STR( (( (nLinPlan-1) / TMP_ITENS->(LastRec()) )*100),3)+"%")
oSheet:Cells( nLinPlan, 1 ):Value := Alltrim(TMP_ITENS->codi)
oSheet:Cells( nLinPlan, 2 ):Value := Alltrim(TMP_ITENS->Desc)
oSheet:Cells( nLinPlan, 3 ):Value := TMP_ITENS->Qtde
oSheet:Cells( nLinPlan, 4 ):Value := TMP_ITENS->ESTQATUAL
oSheet:Cells( nLinPlan, 5 ):Value := TMP_ITENS->VL_TOT/TMP_ITENS->QTDE
oSheet:Cells( nLinPlan, 6 ):Value := TMP_ITENS->VL_TOT
//-- Totaliza
ntotQtd += TMP_ITENS->Qtde
nTotValor += TMP_ITENS->Vl_TOT
// Formatar célula:
oSheet:Cells( nLinPlan, 1 ):NumberFormat := "000000"
oSheet:Cells( nLinPlan, 4 ):NumberFormat := "#.##0,00"
oSheet:Cells( nLinPlan, 5 ):NumberFormat := "#.##0,00"
oSheet:Cells( nLinPlan, 6 ):NumberFormat := "#.##0,00"
//oExcel.ActiveSheet.UsedRange.EntireColumn.Autofit
// Alinhamento das celulas:
oSheet:Cells( nLinPlan, 1 ):HorizontalAlignment := 3 //-- Centro
oSheet:Cells( nLinPlan, 5 ):HorizontalAlignment := 4 //-- Right
oSheet:Cells( nLinPlan, 6 ):HorizontalAlignment := 4 //-- Right
cIntervalo := 'A' + ALLTRIM(STR(nLinPlan)) + ':F' + ALLTRIM(STR(nLinPlan))
nLinPlan++
TMP_ITENS->( DBSKIP() )
END
oSheet:Cells( nLinPlan, 4 ):Value := ntotQtd
oSheet:Cells( nLinPlan, 4 ):Font:Bold := .T.
oSheet:Cells( nLinPlan, 4 ):Font:ColorIndex := 02 //-- Cor da letra Branca
oSheet:Cells( nLinPlan, 4 ):HorizontalAlignment := 4 //-- Right
oSheet:Cells( nLinPlan, 4 ):NumberFormat := "#.##0,00"
oSheet:Cells( nLinPlan, 6 ):Value := nTotValor
oSheet:Cells( nLinPlan, 6 ):Font:Bold := .T.
oSheet:Cells( nLinPlan, 6 ):Font:ColorIndex := 02 //-- Cor da letra Branca
oSheet:Cells( nLinPlan, 6 ):HorizontalAlignment := 4 //-- Right
oSheet:Cells( nLinPlan, 6 ):NumberFormat := "#.##0,00"
oSheet:Range( 'A' + ALLTRIM(STR(nLinPlan)) + ':F' + ALLTRIM(STR( nLinPlan ))):Interior:ColorIndex := 21
// Colocar Bordas:
cIntervalo := 'A1:F' + ALLTRIM(STR( nLinPlan ) )
oSheet:Range(cIntervalo):Borders(1):LineStyle:= 1
oSheet:Range(cIntervalo):Borders(2):LineStyle:= 1
oSheet:Range(cIntervalo):Borders(3):LineStyle:= 1
oSheet:Range(cIntervalo):Borders(4):LineStyle:= 1
* Retrieve the FileFormat
nFileFormat = oExcel:WorkBooks(1):FileFormat
cArq := CurDirSys() + 'ProdOrcAgrp' + cTerminal + '.xls'
Ferase( cArq)
oSheet:SaveAs( cArq, 56 ) // Salva no Excel 8.0// AKI VC DEFINE A VERSAO DO TEU EXCEL... QTO MAIOR MAIS ATUAL... EU COLOQUEI A 8 Q ABRE MEIO Q EM TODOS HJ MAS PODE COLOCAR MAIS ALTA
inkey(1)
Executa(cArq) // AKI ABRE A PLANILHA EQUIVALENTE A RUN NOMEDAPLANILHA.XLS
oExcel:WorkBooks:Close()
oExcel:Quit()
oExcel := NIL // Libera o Excel
DBCLOSEALL()
RETURN
Aki segue uma prévia das versoes... eu uso a 8, a XLSX deve ser a 12
1987 Excel 2.0 para Windows (Existiu uma versão do excel para DOS, mas não teve aceitacao)
1990 Excel 3.0
1992 Excel 4.0
1993 Excel 5.0 (Office 4.2 & 4.3, versão 32-bit apenas para Windows NT )
1995 Excel 7.0 (Office '95)
1997 Excel 8.0 (Office '97)
1999 Excel 9.0 (Office 2000)
2001 Excel 10.0 (Office XP)
2003 Excel 11.0 (Office 2003)
2007 Excel 12.0 (Office 2007
[]´s