Visual Basic.NET - Importar archivo texto a Excel desde VB.Net

 
Vista:

Importar archivo texto a Excel desde VB.Net

Publicado por Rober (7 intervenciones) el 09/12/2007 17:12:54
Hola a todos, aquí viene mi problema, espero que alguien me pueda ayudar:
Trato de importar un archivo de texto a una hoja excel y trato de hacerlo del siguiente modo (obtenido a partir de la modificación de una macro grabada en excel con el grabador de macros):

With hojatabla.QueryTables.Add(Connection:= _
"TEXT;" & Ruta _
, Destination:=hojatabla.Range(celda_ini))
.Name = "archivo importado"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = XlCellInsertionMode.xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = XlTextParsingType.xlDelimited
.TextFileTextQualifier = XlTextQualifier.xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1) ' AQUI VIENE EL PROBLEMA
.TextFileTrailingMinusNumbers = True
.Refresh(BackgroundQuery:=False)
End With

El problema está aquí:

.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1)

Me da problemas la propiedad "TextFileColumnDataTypes" , no se como definirla, parece que hay problemas al definir esa matriz, no lo se. La he tomado directamente del grabador de macros donde lógicamente si funciona, pero no se como adaptarlo para que funcione desde VB Net.
Tal y como está el compilador "se queja" diciendo:
"Array es un tipo y no se puede usar como expresión"

Espero que se entienda bien la cuestión. A alguien se le ocurre alguna idea?

Muchas gracias por vuestro tiempo
Un saludo.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Importar archivo texto a Excel desde VB.Net

Publicado por Andrés (1 intervención) el 29/12/2008 15:12:16
hola q tal
estoy teniendo un problema similar al tuyo, tratando de convertir un archivo de texto a un xls, y el compilador me da el mismo problema con Array...quisiera saber si has podido encontrar una solución
muchas gracias y saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Importar archivo texto a Excel desde VB.Net

Publicado por Rober (7 intervenciones) el 29/12/2008 21:08:58
Hola Andrés.

Lo dejé así y funcionó:

With hoja.QueryTables.Add(Connection:= _
"TEXT;" & Ruta_
, Destination:=hoja.Range("A1"))
.Name = "FicheroExcel"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = XlCellInsertionMode.xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = XlTextParsingType.xlDelimited
.TextFileTextQualifier = XlTextQualifier.xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True 'delimitador tabulación!!!
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True ' delimitador espacio
.TextFileTrailingMinusNumbers = True
.Refresh(BackgroundQuery:=False)
End With

Espero que te sirva de ayuda.

Un saludo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Importar archivo texto a Excel desde VB.Net

Publicado por pablo (1 intervención) el 19/06/2009 19:12:47
En ecxel vas a Datos_obtener datos externos
Buscas la el archivo que queres exportar, doble clic y segui los pasos.-
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar