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.
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


0