Aqui está um trecho de código para vossa analise e implementação:
Function XLSTabela()
LOCAL oExcel, oHoja
LOCAL nRow := 1, nCol
M->NUM_TEMP := STRZERO(RANDOM(9999),4)
M->DBF_TEMP := cPath+"\PN"+M->NUM_TEMP+".DB$"
M->NTX_TEMP := cPath+"\PN"+M->NUM_TEMP+".CD$"
CursorWait()
oExcel := TOleAuto():New( "Excel.Application" )
oExcel:WorkBooks:Add()
oHoja := oExcel:Get( "ActiveSheet" )
nRows := oHoja:UsedRange:Rows:Count()
nCols := oHoja:UsedRange:Columns:Count()
oHoja:PageSetup:Orientation := 2
oHoja:PageSetup:PrintGridlines := .t.
// Margens
oHoja:PageSetup:LeftMargin := 0.25
oHoja:PageSetup:RightMargin := 0.25
oHoja:PageSetup:TopMargin := 0.25
oHoja:PageSetup:BottomMargin := 0.25
oHoja:PageSetup:HeaderMargin := 0.25
oHoja:PageSetup:FooterMargin := 0.25
// oExcel:WorkBooks:Add()
// oSheet = oExcel:ActiveSheet
// oSheet:Cells( 1, 1 ):Value = "This is the first page"
// oSheet:Rows( 2 ):PageBreak = xlPageBreakManual
// oSheet:Cells( 2, 1 ):Value = "This is the second page"
// oExcel:Visible = .T.
// Area de Impressao
oHoja:PageSetup:PrintArea = "$A$1:$O$60"
// Area de Impressao
//oRange := oExcel:Range("A10:A10"):Select()
//oHoja:HPageBreaks := oRange
//oRange := oHoja:Cells(60,15):Select()
//oHoja:HPageBreaks:Add( oHoja:Range("A60:o60") )
//oPageBreak:Add( oRange )
//oHoja:HPageBreaks:Add( oHoja:Cells( 60, 14 ):Select() )
//oHoja:VPageBreaks:Add( "" )
//oHoja:HPageBreaks:Add( "A60" )
//oHoja:VPageBreaks:Add( "O60" )
// Define nome para planilha
//oHoja:= oExcel:sheets:item(1)
oHoja:name:='Tabela de Precos'
//oSheet:Range("A:A"):Set("ColumnWidth",32) // AJUSTA TAMAÑO UN RANGO A UN VALOR
// Toda planilha
oHoja:Cells:Font:Name := "Arial"
oHoja:Cells:Font:Size := 8
dbSelectArea( "ESTOQUE" )
@ tableXLS SELECT descricao,valorvenda ;
FROM estoque TO (DBF_TEMP)
USE (DBF_TEMP) ALIAS tableXLS NEW
INDEX ON descricao TO (NTX_TEMP)
SET INDEX TO (NTX_TEMP)
// Formatando o titulo
oHoja:Cells( 1, 1 ):Value := "FABRICA PET - WWW.FABRICAPET.COM.BR"
oHoja:Cells( 1, 1 ):Font:Size := 24
oHoja:Cells( 1, 1 ):Font:Name := "Arial"
oHoja:Range( "A1:O1" ):HorizontalAlignment := 7
oHoja:Cells( 1, 1 ):Select()
nRow := 2
nCol := 1
DO WHILE .T. // EOF()
if nRow = 2
//oSheet:Range("A:A"):Set("ColumnWidth",32) // AJUSTA TAMAÑO UN RANGO A UN VALOR
// Colocando nomes nas colunas
oHoja:Cells( nRow, nCol+0 ):Value := "DESCRICAO"
oHoja:Cells( nRow, nCol+1 ):Value := "PRECO"
oHoja:Cells( nRow, nCol+2 ):Value := "QT"
// Formatando estilo
oHoja:Cells( nRow, nCol+0 ):Font:Bold := .T. // :Font:Size / :Font:Color
oHoja:Cells( nRow, nCol+1 ):Font:Bold := .T.
oHoja:Cells( nRow, nCol+2 ):Font:Bold := .T.
// Formatando tamanho
oHoja:Cells( nRow, nCol+0 ):ColumnWidth := 22
oHoja:Cells( nRow, nCol+1 ):ColumnWidth := 6
oHoja:Cells( nRow, nCol+2 ):ColumnWidth := 5
oHoja:Cells( nRow, nCol+3 ):ColumnWidth := 0.25
// Formatando tamanho
oHoja:Cells( nRow, nCol+0 ):Interior:ColorIndex := 6
oHoja:Cells( nRow, nCol+1 ):Interior:ColorIndex := 6
oHoja:Cells( nRow, nCol+2 ):Interior:ColorIndex := 6
//
nRow := 3
endif
// Formatando um campo
oHoja:Cells( nRow, nCol+0 ):Value := descricao
oHoja:Cells( nRow, nCol+1 ):NumberFormat := "##.##0,00"
oHoja:Cells( nRow, nCol+1 ):Value := valorvenda
// Calcula quantidade * valorvenda
oHoja:Cells( nRow, nCol+3 ):NumberFormat := "##.##0,00"
oHoja:Cells( nRow, nCol+3 ):Value := "="+chr(64+nCol+1)+alltrim(str(nRow))+"*"+chr(64+nCol+2)+alltrim(str(nRow))
// Somatoria dos subtotais
//oHoja:Cells( nRow, nCol+1 ):NumberFormat := "##.##0,00"
//oHoja:Cells( nRow, nCol+1 ):Value := "=soma("+chr(64+nCol+2)+"3:"+chr(64+nCol+2)+"57)"
//
oHoja:Cells( nRow, nCol+0 ):Font:Bold := .T.
oHoja:Cells( nRow, nCol+1 ):Font:Bold := .T.
//
oHoja:Cells( nRow, nCol+2 ):Interior:ColorIndex := 6
//
nRow := nRow + 1
if nRow > 57 .or. eof()
if eof() .and. nRow < 57
nRow := 58
endif
oHoja:Cells( nRow, nCol+1 ):NumberFormat := "##.##0,00"
oHoja:Cells( nRow, nCol+1 ):Value := "=soma("+chr(64+nCol+3)+"3:"+chr(64+nCol+3)+"57)"
oHoja:Cells( nRow, nCol+1 ):Font:Italic := .T.
nRow := 2
nCol := nCol + 4
if eof()
exit
endif
endif
SKIP
ENDDO
//
oHoja:Cells( 59, 1 ):Value := "SUBTOTAL"
oHoja:Cells( 59, 1 ):Font:Bold := .T.
oHoja:Cells( 59, 1 ):Font:Size := 10
oHoja:Cells( 60, 1 ):NumberFormat := "####.##0,00"
oHoja:Cells( 60, 1 ):Value := "=B58+F58+J58+N58"
oHoja:Cells( 60, 1 ):Font:Italic := .T.
oHoja:Cells( 60, 1 ):Font:Bold := .T.
//
oHoja:Cells( 59, 5 ):Value := "DESCONTO"
oHoja:Cells( 59, 5 ):Font:Bold := .T.
oHoja:Cells( 59, 5 ):Font:Size := 10
oHoja:Cells( 60, 5 ):NumberFormat := "####.##0,00"
//oHoja:Cells( 60, 5 ):Value := "=B58+F58+J58+N58"
oHoja:Cells( 60, 5 ):Font:Italic := .T.
oHoja:Cells( 60, 5 ):Font:Bold := .T.
//
oHoja:Cells( 59, 9 ):Value := "TOTAL GERAL"
oHoja:Cells( 59, 9 ):Font:Bold := .T.
oHoja:Cells( 59, 9 ):Font:Size := 10
oHoja:Cells( 60, 9 ):NumberFormat := "####.##0,00"
oHoja:Cells( 60, 9 ):Value := "=A60-(A60*(E60*0,01))"
oHoja:Cells( 60, 9 ):Font:Italic := .T.
oHoja:Cells( 60, 9 ):Font:Bold := .T.
//
dbSelectArea( "ESTOQUE" )
//
oExcel:Visible := .T.
//oHoja:PrintOut() // Funciona OK
//oExcel:WorkBooks:SaveAs(cFilePath(GetModuleFileName(GetInstance()))+"\FABRICA.xls")
oHoja:End()
oExcel:End()
RETURN
Com ele voce poderá gerar uma planilha mais complexa com mais firulas que o normal. Ela faz uso de outra contribuição aqui existente aqui