Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

Excel Interop w/ VB.NET

$
0
0

Good Afternoon Everyone -

I am having difficulty accomplishing a few specific features within Excel Interop.  I can successfully open a text file using .OpenText but can't get the following things to occur - issue #2 is critical.  I am using VS2013, Framework 4.0 or 4.5, and Excel 2013 with Interoperability Libraries v15.0 loaded

1.  Autosize Fields to maximum size
2.  Field Type to be defined as "Text" to prevent leading Zero's from being dropped

I've read countless forums and google results but nothing works, I'm still loosing my leading zero's.  The code I'm using for the current process is below and any help for field formatting would be greatly appreciated.

Dim excelapp As New Microsoft.Office.Interop.Excel.Application

Dim Filename As String = file2convert
Dim Origin As Object = Excel.XlPlatform.xlWindows
Dim StartRow As Object = 1
Dim DataType As Object = Excel.XlTextParsingType.xlDelimited
Dim TextQualifier As Object
Dim ConsecutiveDelimiter As Object = False
Dim Tab As Object
Dim Semicolon As Object
Dim Comma As Object
Dim Space As Object
Dim Other As Object = False
Dim OtherChar As Object = False

excelapp.Workbooks.OpenText(Filename, Origin, StartRow, DataType, TextQualifier, ConsecutiveDelimiter, Tab, Semicolon, Comma, Space, Other, OtherChar)

excelapp.displayalerts = False
excelapp.ActiveWorkbook.SaveAs(Filename:=newfile, FileFormat:=51)
excelapp.ActiveWorkbook.Close(SaveChanges:=True)
excelapp.DisplayAlerts = True
excelapp.Quit()
excelapp = Nothing

--BCCGeorge


Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>