Havanamild
Programmer
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
);
}
}
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
);
}
}