running text import wizard through c#

C

cakewalkr7

I have a data file that I need to download and convert from text to xls to
then do further manipulation. When I manually fire up excel, open the text
file and leave all the text import wizard defaults I can then work with the
resulting xls file programmatically. When I use the following code I get
errors when I try to open the resulting xls file. I haven't been able to
find much about the different options in the OpenText file command so I'm not
sure what properties I'm setting incorrectly that the wizard automatically
sets correctly. It's a tab delimited file. Can anyone tell me what options
I need to set to get it converted correctly? Thanks.

Excel.Application application = new Excel.Application();
object missing = System.Reflection.Missing.Value;
System.Threading.Thread.CurrentThread.CurrentCulture = new
CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentUICulture = new
CultureInfo("en-US");
application.Caption = "Test";
application.Visible = true;
application.Workbooks.OpenText
(
sFileToSave,
missing,
1,
Excel.XlTextParsingType.xlDelimited,
Excel.XlTextQualifier.xlTextQualifierNone,
missing,
true, //TAB
missing,
false, //COMMA
missing,
missing,
missing,
missing,
missing,
missing,
missing,
missing,
missing
);

application.Save(sExcelToSave);
application.Quit();
application = null;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top