Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel WorkBook.OpenText Method in C#

Status
Not open for further replies.

Havanamild

Programmer
Mar 7, 2006
2
CA
I am trying to bring a CSV file into Excel. I have been sucessful but I can not get the XlColumnDataType to set properly under the FieldInfo parameter. The link below provides an example that looks like this

Array(Array(0, 1), Array(10, 9), Array(15, 1))

I think this is Visual Basic, does any one know how I would show this in C#. My code below compiles but it does not set the ColumnDataTypes, they come in as default.

Thank you in advance for the help it is much appreciated.

Havanamild



My Code:

class CSV2Excel
{
public static void OpenTxtInExcel( string filename)
{
Excel.Application application = new Excel.Application();
object missing = System.Reflection.Missing.Value;

int[,] fieldInfo = new int[4, 2] { { 1, 2 }, { 2, 4 }, { 3, 2 }, { 4, 2 } };
object oFieldInfo = fieldInfo;
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
application.Visible = true;
application.Workbooks.OpenText
(
filename,
Excel.XlPlatform.xlWindows, //Origin
1,// Start Row
Excel.XlTextParsingType.xlDelimited,//Datatype
Excel.XlTextQualifier.xlTextQualifierNone,//TextQualifier
false, // Consecutive Deliminators
false, // tab
false, // semicolon
true, //COMMA
false, // space
false, // other
missing, // Other Char
oFieldInfo, // FieldInfo
missing, //TextVisualLayout
missing, // DecimalSeparator
missing, // ThousandsSeparator
missing, // TrialingMionusNumbers
missing //Local
);

}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top