// //********************************************************************************************** // public List<TMeteo> ReadPrecipitation(String aFile, DateTime aFirst, DateTime aLast) { Double OldValue = 0.0; Double NewValue = 0.0; Int32 FirstMonth = aFirst.Month; Int32 LastMonth = aLast.Month; String SheetName; List<TMeteo> Prec = new List<TMeteo> (); Prec.Clear(); MyWorkBook = ExcelApp.Workbooks.Open(aFile, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing); for (Int32 Month = FirstMonth; Month <= LastMonth; Month++) { OldValue = 0.0; SheetName = GetNameOfMonth(Month); MyWorkSheet = (Worksheet)MyWorkBook.Worksheets.get_Item(SheetName); Range MyRange = MyWorkSheet.UsedRange; System.Array MyValues = (System.Array)MyRange.Cells.get_Value(XlRangeValueDataType.xlRangeValueDefault); String[,] MyData = ConvertToStringArray(MyValues); for (Int32 i = 0; i < MyData.GetLength(0); i++) { TMeteo MyMeteo = new TMeteo(); if ((MyData[i, 0].IndexOf("/") >= 0) || (MyData[i,0].IndexOf("-") >= 0)) { MyMeteo.Date = Convert.ToDateTime(MyData[i, 0]); NewValue = Convert.ToDouble(MyData[i, 1]); MyMeteo.Value = NewValue - OldValue; OldValue = NewValue; Prec.Add(MyMeteo); } } } MyWorkBook.Close(false, "", null); return Prec; }
// //********************************************************************************************** // public List<TMeteo> ReadIrrigation(String aFile) { Double NewValue = 0.0; String SheetName = @"Irrigation"; List<TMeteo> Irrig = new List<TMeteo>(); Irrig.Clear(); MyWorkBook = ExcelApp.Workbooks.Open(aFile, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing); try { try { MyWorkSheet = (Worksheet)MyWorkBook.Worksheets.get_Item(SheetName); Range MyRange = MyWorkSheet.UsedRange; System.Array MyValues = (System.Array)MyRange.Cells.get_Value(XlRangeValueDataType.xlRangeValueDefault); String[,] MyData = ConvertToStringArray(MyValues); for (Int32 i = 1; i < MyData.GetLength(0); i++) { TMeteo MyMeteo = new TMeteo(); if ((MyData[i, 0].IndexOf("-") >= 0) || (MyData[i, 0].IndexOf("/") >= 0)) { MyMeteo.Date = Convert.ToDateTime(MyData[i, 0]); NewValue = Convert.ToDouble(MyData[i, 1]); MyMeteo.Value = NewValue; Irrig.Add(MyMeteo); } } } catch (Exception e) { MessageBox.Show("??? Error opening sheet Irrigation in file " + aFile + ": " + e.Message); } } finally { MyWorkBook.Close(false, "", null); } return Irrig; }