Exemplo n.º 1
0
        internal static IDictionary <string, object> GetEmptyExpandoObject(int maxColumnIndex, int startCellIndex)
        {
            var cell = new Dictionary <string, object>();

            for (int i = startCellIndex; i <= maxColumnIndex; i++)
            {
                var key = ColumnHelper.GetAlphabetColumnName(i);
                if (!cell.ContainsKey(key))
                {
                    cell.Add(key, null);
                }
            }
            return(cell);
        }
Exemplo n.º 2
0
        internal static List <ExcelColumnInfo> GetExcelCustomPropertyInfos(Type type, string[] keys, Configuration configuration)
        {
            List <ExcelColumnInfo> props = GetExcelPropertyInfo(type, BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.Instance, configuration)
                                           .Where(prop => prop.Property.GetSetMethod() != null &&
                                                  !prop.Property.GetAttributeValue((ExcelIgnoreAttribute x) => x.ExcelIgnore) &&
                                                  !prop.Property.GetAttributeValue((ExcelColumnAttribute x) => x.Ignore))
                                           .ToList() /*ignore without set*/;

            if (props.Count == 0)
            {
                throw new InvalidOperationException($"{type.Name} un-ignore properties count can't be 0");
            }

            {
                var withCustomIndexProps = props.Where(w => w.ExcelColumnIndex != null && w.ExcelColumnIndex > -1);
                if (withCustomIndexProps.GroupBy(g => g.ExcelColumnIndex).Any(_ => _.Count() > 1))
                {
                    throw new InvalidOperationException($"Duplicate column name");
                }
                var maxkey   = keys.Last();
                var maxIndex = ColumnHelper.GetColumnIndex(maxkey);
                foreach (var p in props)
                {
                    if (p.ExcelColumnIndex != null)
                    {
                        if (p.ExcelColumnIndex > maxIndex)
                        {
                            throw new ArgumentException($"ExcelColumnIndex {p.ExcelColumnIndex} over haeder max index {maxkey}");
                        }
                        if (p.ExcelColumnName == null)
                        {
                            throw new InvalidOperationException($"{p.Property.DeclaringType.Name} {p.Property.Name}'s ExcelColumnIndex {p.ExcelColumnIndex} can't find excel column name");
                        }
                    }
                }
            }

            return(props);
        }