Hello,
I've got a Problem with importing a CSV file to Excel via C#.
I've got 2 different types of CSV files, the first one is delimitered by commas and the import works perfectly fine, the second type is delimitered by tabstops and is not working. I can't find any mistake so I hope you are going to find a solution:
Code for Importing comma file:
Microsoft.Office.Interop.Excel.Application xl = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Worksheet xSheet;
Microsoft.Office.Interop.Excel.Range xRange;
xl.Workbooks.OpenText(tbDS.Text,
false, 3,
Excel.XlTextParsingType.xlDelimited,
Excel.XlTextQualifier.xlTextQualifierNone,
Type.Missing, Type.Missing, Type.Missing, true,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing);
Code for Importing tab file:
string file = Path.GetDirectoryName(tbDS.Text) + "\\Measurements\\" + report + ".csv";
if (File.Exists(file))
{
Microsoft.Office.Interop.Excel.Application xl = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Worksheet xSheet;
Microsoft.Office.Interop.Excel.Range xRange;
xl.Workbooks.OpenText(file,
false, 3,
Excel.XlTextParsingType.xlDelimited,
Excel.XlTextQualifier.xlTextQualifierNone,
Type.Missing, true, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing);
First one splits the CSV perfectly fine, second one does not split the CSV File
Sample CSV:
comma:
Testplan, Load, RFV1, 1HAR1, RFV2, 1HAR2, RR, LRU, LRL, TUZ(pp), TUZ(har), Total grade, date + time,
434, 6326, 59, 19, 0, 0, 0.249, 1.108, 0.66, 17.3, 0, 1, 7. 05. 2014 08:54:09,
434, 6334, 129, 95, 0, 0, 0.352, 1.449, 0.931, 27.8, 0, 4, 7. 05. 2014 08:54:25,
434, 6301, 41, 23, 0, 0, 0.129, 1.032, 0.631, 14.5, 0, 1, 7. 05. 2014 08:54:40,
434, 6317, 76, 34, 0, 0, 0.248, 1.011, 0.774, 18, 0, 1, 7. 05. 2014 08:54:57,
tab:
RKS1 RKS2 LKS1 LKS2 HS SSO SSU
6 0 2 0 -47 0 -44
6 0 2 0 -49 1 -48
6 0 2 0 -50 2 -54
6 0 2 0 -51 3 -60
6 0 2 0 -52 5 -66
6 0 1 0 -54 5 -70
Thank you in Advance