Exportar de Datagridviewer A Excell
Exportar de Datagridviewer A Excell
Di.in exApp As 1,ie,., M.ic::rosof t .Of fice .In te,..op. Excel. Applica tion
Ditn exlib,..o As Microsof t .Of f ice .lrrte,..op. Excel.l.Jor-
kbook Ditn ex:Hoja As Microsof t .Off ice. Ioterop .Excel
.t.Jorkshee t Try
exlibro = eXApp.wor-kbooks .Add 'crea el libr-o de excel
exHoja = exlibro .1-lorksh eets.Add()
'cuenta filas y colu•nas
Oim NCol As Integer = miOataGridView
.ColumnCount Oim NRO\\I As Integer =
r.i iOataGridView .Ro\'1Count
For iAs Integer = 1 To llCol
exHoj a .Cells.Iter.i( l, i} = miOataGridViel1.Colum:1s{i - l) .llame
.ToString Hext
For Fila As Integer = 9 To NRolot • 1
For Col As Integer • 0 To NCol - 1
exMoja .Ce lls.Item ( F ila + 2 Col •t- 1} • m.iDa taGridViel1.Ro\1s( F ila)
.Cells(Col) .Value Hext
N ext
exHoj a .ROl1S. Itern (l) .f on t .Bold = 1 ' t itulo en negr itas
ex:Hoja .R0\1S. Item(l) .Hor izootalAlignmen t = 3 ·alineación a l cen tr-o
exHoja .Columns.Au tof it () ' autoajus te de la columna
exHoja .Columns. HorizontalAlignrnent = 2
exApp .Applicatio .V isible = True
exHoja = f4othing
exlibro = Nothing
exApp = Nothing
Catch ex As Exception
Msgaox ( ex.Message MsgSoxStyle..Critic;;i l •error a l exportar a
Excel'* ) Retu rn False
End Try
Returo True
End Function
Ptivate Sub Buttonl_Click(sendet As System .Object e As System .EvntArgs)Handles Buttonl.Click
1
C•ll GridAE<<•l(OJtaGridViowl}
End Sub