Esempio n. 1
0
        private void Write(ExcelManager manager, object target)
        {
            HandleCommonClassAttributes(manager, target);

            //static cells
            target.GetProperties().ForEach(p =>
            {
                object value = target.GetPropertyValue(p.Name);
                if (p.HasAttribute <ToCellAttribute>())
                {
                    ToCellAttribute toCell = p.Attribute <ToCellAttribute>();
                    if (toCell != null)
                    {
                        manager.SetValue(toCell.CellAddress, value);
                    }
                }
                else if (p.HasAttribute <ToRangeAttribute>())
                {
                    ToRangeAttribute toRange = p.Attribute <ToRangeAttribute>();
                    if (value is IList)
                    {
                        manager.SetRangeValues(toRange.StartCellAddress, toRange.EndCellAddress, (IList)value);
                    }
                    else
                    {
                        manager.SetRangeValue(toRange.StartCellAddress, toRange.EndCellAddress, value);
                    }
                }
            });

            target.GetProperties().FindAll(p => p.HasAttribute <ToDynamicRangeAttribute>()).ForEach(p =>
            {
                object value = target.GetPropertyValue(p.Name);
                if (value is IList)
                {
                    IList list = value as IList;
                    ToDynamicRangeAttribute dr = p.Attribute <ToDynamicRangeAttribute>();
                    int startRow = dr.StartRow;
                    for (int i = 1; i < list.Count; i++)
                    {
                        manager.CopyRows(startRow, startRow, startRow + 1);
                        startRow++;
                    }
                    for (int i = 0; i < list.Count; i++)
                    {
                        var item = list[i];
                        if (item is IList)
                        {
                            manager.SetRangeValues(
                                string.Format("{0}{1}", dr.StartColumnName, dr.StartRow + i),
                                string.Format("{0}{1}", dr.EndColumnName, dr.StartRow + i + list.Count - 1),
                                (item as IList));
                        }
                    }
                }
            });
        }