Пример #1
0
        /// <summary>
        /// Load a collection into the worksheet starting from the top left row of the range.
        /// </summary>
        /// <typeparam name="T">The datatype in the collection</typeparam>
        /// <param name="collection">The collection to load</param>
        /// <param name="paramsConfig"><see cref="Action{LoacFromCollectionParams}"/> to provide parameters to the function</param>
        /// <example>
        /// <code>
        /// sheet.Cells["C1"].LoadFromCollection(items, c =>
        /// {
        ///     c.PrintHeaders = true;
        ///     c.TableStyle = TableStyles.Dark1;
        /// });
        /// </code>
        /// </example>
        /// <returns>The filled range</returns>
        public ExcelRangeBase LoadFromCollection <T>(IEnumerable <T> collection, Action <LoadFromCollectionParams> paramsConfig)
        {
            var param = new LoadFromCollectionParams();

            paramsConfig.Invoke(param);
            if (collection is IEnumerable <IDictionary <string, object> > )
            {
                if (param.Members == null)
                {
                    return(LoadFromDictionaries(collection as IEnumerable <IDictionary <string, object> >, param.PrintHeaders, param.TableStyle));
                }
                return(LoadFromDictionaries(collection as IEnumerable <IDictionary <string, object> >, param.PrintHeaders, param.TableStyle, param.Members.Select(x => x.Name)));
            }
            var func = new LoadFromCollection <T>(this, collection, param);

            return(func.Load());
        }
Пример #2
0
        /// <summary>
        /// Load a collection into the worksheet starting from the top left row of the range.
        /// </summary>
        /// <typeparam name="T">The datatype in the collection</typeparam>
        /// <param name="Collection">The collection to load</param>
        /// <param name="PrintHeaders">Print the property names on the first row. Any underscore in the property name will be converted to a space. If the property is decorated with a <see cref="DisplayNameAttribute"/> or a <see cref="DescriptionAttribute"/> that attribute will be used instead of the reflected member name.</param>
        /// <param name="TableStyle">Will create a table with this style. If set to TableStyles.None no table will be created</param>
        /// <param name="memberFlags">Property flags to use</param>
        /// <param name="Members">The properties to output. Must be of type T</param>
        /// <returns>The filled range</returns>
        public ExcelRangeBase LoadFromCollection <T>(IEnumerable <T> Collection, bool PrintHeaders, TableStyles TableStyle, BindingFlags memberFlags, MemberInfo[] Members)
        {
            if (Collection is IEnumerable <IDictionary <string, object> > )
            {
                if (Members == null)
                {
                    return(LoadFromDictionaries(Collection as IEnumerable <IDictionary <string, object> >, PrintHeaders, TableStyle));
                }
                return(LoadFromDictionaries(Collection as IEnumerable <IDictionary <string, object> >, PrintHeaders, TableStyle, Members.Select(x => x.Name)));
            }
            var param = new LoadFromCollectionParams
            {
                PrintHeaders = PrintHeaders,
                TableStyle   = TableStyle,
                BindingFlags = memberFlags,
                Members      = Members
            };
            var func = new LoadFromCollection <T>(this, Collection, param);

            return(func.Load());
        }