View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
cakewalkr7 cakewalkr7 is offline
external usenet poster
 
Posts: 1
Default running text import wizard through c#

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.CurrentCultu re = new
CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentUICul ture = 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;