Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/08/2010, 13:55
Avatar de Carlojas
Carlojas
 
Fecha de Ingreso: junio-2007
Ubicación: Shikasta
Mensajes: 1.272
Antigüedad: 16 años, 10 meses
Puntos: 49
Llenar DataGridView Con Archivo Excel

Compañeros buenas tardes, tengo el siguiente inconveniente estoy intentando cargar un Datagrid con el contenido de un archivo de excel si hago el procedimiento con un archivo excel 2003 no hay inconveniente pero si lo intento hacer con un archivo excel 2007 hay parece un mensaje de error "La tabla externa no tiene el formato esperado." el código que utilizo para dicho procedimiento es el siguiente:

Código vb:
Ver original
  1. Dim Ruta As String
  2.         buscador.ShowDialog()
  3.         Ruta = buscador.FileName
  4.         If Path.GetExtension(Ruta) = ".xls" Or Path.GetExtension(Ruta) = ".xlsx" Then
  5.             Try
  6.                 Dim Conexion As New OleDb.OleDbConnection
  7.                 Dim Adaptador As New OleDbDataAdapter
  8.                 Dim CadenaConexion = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  9.                         "Data Source=" + Ruta + ";" + "Extended Properties=Excel 8.0;"
  10.                 Conexion = New OleDb.OleDbConnection(CadenaConexion)
  11.                 Adaptador = New OleDb.OleDbDataAdapter("SELECT * FROM [Hoja1$]", Conexion)
  12.                 Sdataset = New DataSet()
  13.                 Adaptador.Fill(Sdataset, "Hoja1$")
  14.                 Sdatatable = Sdataset.Tables(0)
  15.                 Me.grid_listas.DataSource = Sdatatable
  16.                 Me.grid_listas.Font = New Font("Tahoma", 12, FontStyle.Regular, GraphicsUnit.Pixel)
  17.                 Me.grid_listas.ColumnHeadersDefaultCellStyle.Font = New Font("Tahoma", 12, FontStyle.Bold, GraphicsUnit.Pixel)
  18.                 Me.grid_listas.Columns(1).Width = 100
  19.                 Me.grid_listas.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
  20.                 Me.grid_listas.Columns(2).Width = 80
  21.             Catch ex As Exception
  22.                 MessageBox.Show(ex.Message)
  23.             End Try
  24.         Else
  25.             MessageBox.Show("Archivo No Válido", "Excel To Grid", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  26.         End If

Tengo instalado el office 2007 en mi PC

Saludos.
__________________
"SELECT * FROM Mujeres WHERE situacion NOT IN ('CASADAS','CON HIJOS','ATORMENTADAS','CUASI-ENNOVIADAS') AND personalidad <> 'INTENSA'"