示例#1
0
        public SacmigFileData Parse(Stream stream)
        {
            ExcelPackage   excelDocument = new ExcelPackage(stream);
            ExcelWorksheet workSheet     = excelDocument.Workbook.Worksheets.First();

            var startRow    = 1;
            var startColumn = 1;
            var endRow      = workSheet.Dimension.End.Row;
            var endColumn   = workSheet.Dimension.End.Column;

            var data = new SacmigFileData
            {
                ObjectName          = workSheet.Cells[startRow++, 1].Value?.ToString(),
                SubjectOfMonitoring = workSheet.Cells[startRow++, 1].Value?.ToString()
            };
            var keys = ParseHeader(workSheet, startRow, startColumn, endColumn);

            for (int rowId = startRow + 1; rowId <= endRow; rowId++)
            {
                try
                {
                    ParseRow(workSheet, rowId, startColumn, keys, data);
                }
                catch
                {
                    continue;
                }
            }
            return(data);
        }
示例#2
0
        private void ParseRow(ExcelWorksheet worksheet, int row, int startColumn, List <string> keys, SacmigFileData data)
        {
            //first column alays is date!
            var dateValue = worksheet.Cells[row, startColumn].Value;
            var dateTuple = dateValue is double?
                            ParseDateCell((double)dateValue) : ParseDateCell(dateValue.ToString());

            for (int keyIndex = 0; keyIndex < keys.Count; keyIndex++)
            {
                var value = worksheet.Cells[row, startColumn + keyIndex + 1].Value;
                if (value != null)
                {
                    try
                    {
                        var doubleValue = value is double?
                                          (double)value : Double.Parse(value.ToString(), CultureInfo.InvariantCulture);
                        data.AddCharacteristicValue(keys[keyIndex], doubleValue, dateTuple.Item1, dateTuple.Item2);
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
        }