コード例 #1
0
        public List <WindData> ReadFromExcel(string path)
        {
            // Get the input file paths
            FileInfo inputFile = new FileInfo(path);

            //Create a worksheet
            FastExcel.Worksheet worksheet = null;

            // Create an instance of Fast Excel
            using (FastExcel.FastExcel fastExcel = new FastExcel.FastExcel(inputFile, true))
            {
                // Read the rows using worksheet name
                worksheet = fastExcel.Read("Sheet1");

                worksheet = fastExcel.Read(1);
                list      = worksheet.Rows.ToArray().ToList();
                foreach (var item in list)
                {
                    windData = new WindData();
                    foreach (var cellItem in item.Cells)
                    {
                        if (item.RowNumber != 1)
                        {
                            switch (cellItem.ColumnNumber)
                            {
                            case 1:
                                windData.year = cellItem.Value.ToString();
                                break;

                            case 2:
                                windData.month = cellItem.Value.ToString();
                                break;

                            case 3:
                                windData.day = cellItem.Value.ToString();
                                break;

                            case 4:
                                windData.timeUTC = cellItem.Value.ToString();
                                break;

                            case 5:
                                windData.windSpeed = cellItem.Value.ToString();
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    if (item.RowNumber != 1)
                    {
                        listData.Add(FixDirection(windData));
                    }
                }
            }

            return(listData);
        }