私のCSVデータは、何かがこのようになりますされ、それをエクスポートします。読むのcsvマルチコラム&
Device data for period 30/08/2016 to 30/08/2016
Site ID,Time,INC1_MD
VSI-18,2016-08-30 00:00:00,165.954
VSI-18,2016-08-30 00:01:00,14.524
VSI-18,2016-08-30 00:02:00,32.920
VSI-18,2016-08-30 00:03:00,48.508
VSI-18,2016-08-30 00:04:00,62.418
.....
と私は最初の2行を無視して「VSI-18で起動しよう...」 と日付の後&時間欄 ある3列目のデータを抽出し、同様に、新しいCSVファイルに日 につき1列を書き出す:
day1,day2,day3
100,200,300
200,123,123
123,222,444
....
、ここでは、私はまだデータを読み取る方法を見つけ出すことはできませんので、私はまだ完了していないエクスポートデータコードのための私のコード
o_csv_loc.Text = varFile; //csv data file location
save_file_loc.Text = saveloc; //new csv file location
var reader = new StreamReader(File.OpenRead(varFile));
List <string[]> listA = new List<string[]>();
List<string[]> listB = new List<string[]>();
List<string[]> listC = new List<string[]>();
//I think these two code below is to skip first 2 line of csv data
//file and start read the third line (VSI-18...)
reader.ReadLine();
reader.ReadLine();
while (reader.Peek() > -1)
{
var line = reader.ReadLine();
var values = line.Split(';');
listA.Add(new string[] { values[0] });
listB.Add(new string[] { values[1] });
listC.Add(new string[] { values[2] });
//I think that listC is suppose to extract the data after the
//second comma which is third column
}
です。
listB.Add(new string[] { values[1] });
ライン
上のデバッグ、「System.IndexOutOfRangeException」ショーは、このライン上問題になることはありませんされていない場合?値[0]はまだ問題ではありません。EDIT
私はエクスポートデータに成功新しいCSVファイルへ
var reader = new StreamReader(File.OpenRead(varFile));
List <string[]> listA = new List<string[]>(); //here are the code
//changed
List<string[]> listB = new List<string[]>();
List<string[]> listC = new List<string[]>();
reader.ReadLine();
reader.ReadLine();
while (reader.Peek() > -1)
{
var line = reader.ReadLine();
var values = line.Split(',');
listA.Add(new string[] { values[0] });
listB.Add(new string[] { values[1] });
listC.Add(new string[] { values[2]});
}
using (System.IO.TextWriter writer = File.CreateText(saveloc))
{
for (int index = 0; index < listC.Count; index++)
{
writer.WriteLine(string.Join(",", listC[index]) + ',');
}
}
結果がこれです:
165.954,
14.524,
32.920,
48.508,
62.418,
79.151,
96.982,
私はまだ新しい日付を検出し、新しい投入する方法を考え出しますカラム
あなたは ';'で分割しています。私はあなたのファイルにそれらのどれも表示されません。 – Blorgbeard
スニペットマークアップでHTML/JS/CSS以外のコードをラップしないでください。 4つのスペースでインデントするだけで十分です(または強調表示し、 '{}'ボタンをクリックしてください)。 – Blorgbeard
@Blorgbeardが述べたように、私はあなたが '、'の代わりに ';'に分割したいと思う –