示例#1
0
        public void Write(object target, string excelFileName, string templateFileName)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            using (ExcelManager em = new ExcelManager())
            {
                em.Open(templateFileName);
                Write(em, target);
                em.SaveAs(excelFileName);
            }
        }
示例#2
0
        public void Write(object target, string excelFileName, string templateFileName)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            using (ExcelManager em = new ExcelManager())
            {
                em.Open(templateFileName);
                Write(em, target);
                em.SaveAs(excelFileName);
            }
        }
示例#3
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);
                        }
                    }
                }
            }
        }
示例#4
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);
                        }
                    }
                }
            }
        }