Пример #1
0
        static void WriteSoilAnalysis(SoilAnalysis analysis, ISheet sheet, int rowIndex, ICellStyle cellDateStyle)
        {
            var row = CreateAnalysisRow(analysis, sheet, rowIndex, cellDateStyle);

            int i = 2;

            foreach (var p in SoilAnalysis.DoubleProperties.Keys.ToList())
            {
                row.CreateCell(i, CellType.Numeric).SetCellValue((double)Interaction.CallByName(analysis, SoilAnalysis.DoubleProperties[p].Name, CallType.Get));
                i += 1;
            }
        }
Пример #2
0
        static void WriteSoilAnalysisHeader(ISheet sheet)
        {
            var header = sheet.CreateRow(0);

            header.CreateCell(0).SetCellValue(SoilAnalysis.GetDisplayName(nameof(SoilAnalysis.WellName)));
            header.CreateCell(1).SetCellValue(SoilAnalysis.GetDisplayName(nameof(SoilAnalysis.Date)));

            int i = 2;

            foreach (var p in SoilAnalysis.DoubleProperties.Keys.ToList())
            {
                header.CreateCell(i).SetCellValue(p);
                i += 1;
            }
        }
Пример #3
0
        public static List <SoilAnalysis> ReadSoilAnalysis(IWorkbook workbook, int sheetIndex, IProgress <int> progress)
        {
            var  sheet = workbook.GetSheetAt(sheetIndex);
            IRow row;
            List <SoilAnalysis> analyses = new List <SoilAnalysis>();
            int indexError = 1;

            CreateRejectedRows(sheet.GetRow(0));

            try
            {
                var maxCount = sheet.LastRowNum;
                for (int i = 1; i < maxCount + 1; i++)
                {
                    indexError = i;
                    row        = sheet.GetRow(i);
                    var analysis = new SoilAnalysis
                    {
                        Well = GetWell(ReadCellAsString(row, 0)?.ToUpper(CultureInfo.InvariantCulture)),
                        Date = ParseStringDate(ReadCellAsDateString(row, 1))
                    };

                    int j = 2;
                    foreach (var p in SoilAnalysis.DoubleProperties.Keys.ToList())
                    {
                        Interaction.CallByName(analysis, SoilAnalysis.DoubleProperties[p].Name, CallType.Set, ReadCellAsDouble(row, j));
                        j += 1;
                    }

                    if (analysis.Well != null)
                    {
                        analyses.Add(analysis);
                    }
                    else
                    {
                        RejectedRows.Add(CreateRejectedRow(row, j, i, RejectedReasons.WellNotFound));
                    }

                    progress?.Report(i / maxCount * 100);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error leyendo la fila " + indexError.ToString(), ex);
            }

            return(analyses);
        }