Beispiel #1
0
        /// <summary>
        /// ファイル読み込み、実処理
        /// </summary>
        private CSVAllData Read()
        {
            var csvData = new CSVAllData();

            if (IsAccessFile())
            {
                using (FileStream fs = new FileStream(this.F_FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
                    //using (StreamReader sr = new StreamReader(fs, new UTF8Encoding(false)))//BOMなし
                    using (StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("Shift_JIS")))
                    {
                        int maxVal = 0;
                        while (sr.Peek() >= 0)
                        {
                            string lineStr = sr.ReadLine();
                            if (string.IsNullOrEmpty(lineStr))
                            {
                                continue;                           //改行などはとばす
                            }
                            CSVColumnData itemsList = new CSVColumnData();
                            itemsList.MakeListBy(lineStr);
                            csvData.Add(itemsList); //一行分を追加

                            //一番多いカラム数を設定
                            if (maxVal < itemsList.Count)
                            {
                                maxVal = itemsList.Count;
                            }
                        }
                        csvData.MaxColumnsInAllRows = maxVal;
                    }
            }
            return(csvData);
        }