ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   running text import wizard through c# (https://www.excelbanter.com/excel-programming/427197-running-text-import-wizard-through-c.html)

cakewalkr7

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;


All times are GMT +1. The time now is 06:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com