Aunque esto es de VB, he de decirles que es totalente funcional y de gran ayuda para usarla con OLE y la clase TExcel, las he probado casi todas y funcinan muy bien, eliminen lo que no hace falta, espero sea de ayuda a alguien asi como lo fue para mi, copiado textualmente desde la web, saludos...
Generar hoja de Excel desde VB
Prof: Mileti, P.
El primer paso será referenciar a los objetos de Excel que nos permitirán manipular a través de variables objetos tales como laaplicación Excel, un libro o una hoja de cálculo. Para ello desde el menú Proyecto > Referencias seleccionamos Microsoft Excel 10.0 Object Library.
Dim XLApp As Excel.Application
'Aplicación Excel en varaible XLApp
Dim XLBook As Excel.Workbook
'Libro de Excel en variable XLBook
Dim XLSheet As Excel.Worksheet
'Hoja de cálculo en variable XLSheet
Set XLApp = CreateObject("Excel.Application")
Set XLBook = XLApp.Workbooks.Add
Set XLSheet = XLBook.Worksheets(1)
XLSheet.Name = "Informe Nº1"
'Asigna nombre a la hoja XLSheet.Cells.Font.Size = 8
'Toda la hoja con tamaño de fuente de 8
XLApp.Visible = True
'Hace visible Excel
XLSheet.Cells(1, 1).Font.Size = 10
'Tamaño de fuente 10 para celda 1,1
XLSheet.Cells(1, 1).Font.Bold = True
'Celda 1,1 en negrita
XLSheet.Cells(1, 1).Value = "E.E.M.Nº11"
'Escribe en la celda
XLSheet.Range("A3:H4").Font.Bold = True
'El rango A3:H4 esta en negrita
XLSheet.Range("D:E").HorizontalAlignment = xlHAlignCenter
'Columna E y D centradas
XLSheet.Range("A3:H4").HorizontalAlignment = xlHAlignCenter
'Rango centrado
'Ocupar tres celdas con un contenido
XLSheet.Range("D3:F3").HorizontalAlignment = xlHAlignCenterAcrossSelection
'Ancho en cm
XLSheet.Range("A:A").ColumnWidth = 10
XLSheet.Range("B:B").ColumnWidth = 25
XLSheet.Range("C:C").ColumnWidth = 13
XLSheet.Range("D:D").ColumnWidth = 8.5
XLSheet.Range("E:E").ColumnWidth = 8
XLSheet.Range("F:F").ColumnWidth = 10
XLSheet.Range("G:G").ColumnWidth = 10
XLSheet.Range("H:H").ColumnWidth = 25
XLSheet.Cells(3, 1).Value = "CODIGO"
XLSheet.Cells(3, 2).Value = "DIRECCION"
XLSheet.Cells(3, 3).Value = "LOCALIDAD"
XLSheet.Cells(3, 4).Value = "ULTIMA COMPRA"
XLSheet.Cells(4, 4).Value = "FECHA"
XLSheet.Cells(4, 5).Value = "DIAS"
XLSheet.Cells(4, 6).Value = "MONTO"
XLSheet.Cells(3, 7).Value = "PROMEDIO MENSUAL"
XLSheet.Cells(3, 8).Value = "VENDEDORA"
'Alinear verticalmente un contenido
XLSheet.Range("A3:C4").VerticalAlignment = xlVAlignCenter
XLSheet.Range("G3:H4").VerticalAlignment = xlVAlignCenter
'Unir celdas
XLSheet.Range("A3:A4").MergeCells = True
XLSheet.Range("B3:B4").MergeCells = True
XLSheet.Range("C3:C4").MergeCells = True
XLSheet.Range("G3:G4").MergeCells = True
XLSheet.Range("G3:G4").WrapText = True
'El texto al crecer ocupa varias filas de su celda
XLSheet.Range("H3:H4").MergeCells = True
XLSheet.Range("H3:H4").WrapText = True
'Formato de celdas
XLSheet.Range("A:C").NumberFormat = "@"
'Texto
XLSheet.Range("E:E").NumberFormat = "@"
XLSheet.Range("H:H").NumberFormat = "@"
XLSheet.Range("D:D").NumberFormat = "dd/mm/yyyy"
'Fecha
XLSheet.Range("F:G").NumberFormat = "$ ###,##0.00"
'Moneda
'Colorear celdas
XLSheet.Range("A3:H4").Borders.Color = 0
XLSheet.Range("A3:H4").Interior.ColorIndex = 8
'A continuaci
ó
n se podria recorrer un objeto Recordset para generar un informe
For van = 5 To 10
'Instrucciones para escribir en la hoja de acuerdo a un Recordset
Next
'Colorear celdas
XLSheet.Range("A5:H" & van).Interior.ColorIndex = 4
'Crear divisiones horizontales
XLSheet.Range("A5:H" & van).Borders.Color = 0
XLSheet.Range("A5:H" & van).Borders(xlInsideVertical).LineStyle = xlContinuous
XLSheet.Range("A3:H" & van).Borders(xlEdgeLeft).LineStyle = xlContinuous
XLSheet.Range("A3:H" & van).Borders(xlEdgeRight).LineStyle = xlContinuous
XLSheet.Range("A" & van & ":H" & van).Borders(xlEdgeBottom).LineStyle = xlContinuous
'Mantener fijo el encabezado
XLSheet.Range("A5:H5").Select
XLBook.Windows(1).FreezePanes = True
XLSheet.Cells(1, 1).Activate
'Trabajar con una nueva hoja
Set XLSheet = XLBook.Worksheets(2)
XLSheet.Name = "Informe Nº2"
XLSheet.Cells(1, 1).Value = "Hoja 2"
'Liberar variables
Set XLSheet = Nothing
Set XLBook = Nothing
Set XLApp = NothingDios no está muerto...
Gracias a mi Dios ante todo!
Gracias a mi Dios ante todo!