Imports System.Data.OleDb
Public Class Ppal
Inherits System.Windows.Forms.Form
Dim objex As New Excel.Application
Dim libro As Excel.Workbook
Dim hoja As Excel.Worksheet
Dim i As Integer = 9
Dim r As DataRow
Private Sub MiembrosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MiembrosToolStripMenuItem.Click
Try
Dim cn As OleDbConnection = New OleDbConnection
Dim cs As String
cs = "Provider = Mcrosoft.JET.OLEDB.4.0; Data Source = " + Application.StartupPath(+"bd.mdb)")
Dim Da As OleDbDataAdapter
Dim tabla As DataTable
tabla = New DataTable("usuarios")
Dim sql As String
sql = "Select * From usuarios"
libro = objex.Workbooks.Open(Application.StartupPath + "plantillausuarios.xls")
[color=#FF0000]Da = New(sql, cn)[/color]
Da.Fill(tabla)
hoja = libro.Worksheets(1)
hoja.Cells(16, 2) = "Nombre"
hoja.Cells(16, 3) = "Apellido"
hoja.Cells(16, 4) = "Carrera"
hoja.Cells(16, 5) = "Campus"
hoja.Cells(16, 6) = "Expediente"
hoja.Cells(16, 7) = "Telefono"
hoja.Cells(16, 8) = "Correo"
For Each r In tabla.Rows
If tabla.Rows.Count > 0 Then
libro.Worksheets(libro.Worksheets.Count).copy(libro.Worksheets.Count - 1)
hoja.Activate()
hoja.Cells(i, 2) = r.Item("Nombre.")
hoja.Cells(i, 3) = r.Item("Apellido")
hoja.Cells(i, 4) = r.Item("Carrera")
hoja.Cells(i, 5) = r.Item("Campus")
hoja.Cells(i, 6) = r.Item("Expediente")
hoja.Cells(i, 7) = r.Item("Telefono")
hoja.Cells(i, 8) = r.Item("Correo")
hoja.Cells(i, 3) = r.Item(i - 8)
i += 1
End If
Next
objex.Visible = True
objex = Nothing
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub