コード例 #1
0
        public void Read(object destination, string excelFileName)
        {
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }

            using (ExcelManager em = new ExcelManager())
            {
                em.Open(excelFileName);

                HandleCommonClassAttributes(em, destination);

                // Check attributes of Properties in class
                Type objType = destination.GetType();
                foreach (PropertyInfo propInfo in objType.GetProperties())
                {
                    object[] attributes = propInfo.GetCustomAttributes(true);
                    if (attributes == null)
                    {
                        continue;
                    }

                    foreach (Attribute att in attributes)
                    {
                        HandleCommonPropertiesAttributes(em, destination, att, propInfo);

                        // Read Specific Attributes:

                        // [FromCell]
                        FromCell fromCell = att as FromCell;
                        if (fromCell != null)
                        {
                            object value = em.GetValue(fromCell.CellAddress, fromCell.Category);
                            propInfo.SetValue(destination, value, null);
                        }

                        // [FromRange]
                        FromRange fromRange = att as FromRange;
                        if (fromRange != null)
                        {
                            ArrayList values = em.GetRangeValues(fromRange.StartCellAddress, fromRange.EndCellAddress, fromRange.Category);
                            propInfo.SetValue(destination, values, null);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: ExcelMapper.cs プロジェクト: syrotkin/practicas
        public void Read(object destination, string excelFileName)
        {
            if (destination == null)
                throw new ArgumentNullException("destination");

            using (ExcelManager em = new ExcelManager())
            {
                em.Open(excelFileName);

                HandleCommonClassAttributes(em, destination);

                // Check attributes of Properties in class
                Type objType = destination.GetType();
                foreach (PropertyInfo propInfo in objType.GetProperties())
                {
                    object[] attributes = propInfo.GetCustomAttributes(true);
                    if (attributes == null)
                        continue;

                    foreach (Attribute att in attributes)
                    {
                        HandleCommonPropertiesAttributes(em, destination, att, propInfo);

                        // Read Specific Attributes:

                        // [FromCell]
                        FromCell fromCell = att as FromCell;
                        if (fromCell != null)
                        {
                            object value = em.GetValue(fromCell.CellAddress, fromCell.Category);
                            propInfo.SetValue(destination, value, null);
                        }

                        // [FromRange]
                        FromRange fromRange = att as FromRange;
                        if (fromRange != null)
                        {
                            ArrayList values = em.GetRangeValues(fromRange.StartCellAddress, fromRange.EndCellAddress, fromRange.Category);
                            propInfo.SetValue(destination, values, null);
                        }
                    }
                }
            }
        }