Exemplo n.º 1
0
        /// <summary>
        /// 逐行获取Table数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tbDesp"></param>
        /// <param name="getemptyObj"></param>
        /// <param name="validationOperator"></param>
        public string ForEachTableRows <T>(TableDescription tbDesp, SpreadGetTableCollectionParams <T> param, out int upCount)
        {
            tbDesp.NullCheck("tbDesp");
            param.ExportRow.NullCheck("exportRow");
            this.CheckTableExists(tbDesp.TableName);

            StringBuilder customLog = new StringBuilder();
            Table         tb        = this.Tables[tbDesp.TableName];
            int           rowIndex  = 0; upCount = 0;

            foreach (TableRow tr in tb.Rows)
            {
                ExcportRowContext context = new ExcportRowContext()
                {
                    RowIndex = rowIndex
                };
                foreach (TableColumnDescription tc in tbDesp.AllColumns)
                {
                    if (tb.Columns.ContainsKey(tc.ColumnName))
                    {
                        context.PropertyDescriptions.Add(new ExportCellDescription(tc.PropertyName)
                        {
                            TableColumnName = tc.ColumnName, Value = tr[tb.Columns[tc.ColumnName]].Value, Address = CellAddress.Parse(tb.Columns[tc.ColumnName].Position + tb.Address.StartColumn, tr.RowIndex + tb.Address.StartRow + 1).ToString()
                        });
                    }
                }
                ExportRowResult <T> result = param.ExportRow(context);
                customLog.Append(result.ErrorLog);
                rowIndex++;

                if (result.Validated)
                {
                    upCount++;
                }
                else
                if (param.ValidationOperator == ValidationErrorStopMode.Stop)
                {
                    break;
                }
            }

            return(customLog.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 将Excel数据直充到指定的Collection中
        /// </summary>
        /// <typeparam name="T">数据模型</typeparam>
        /// <typeparam name="TCollection">待待充Collection 必须实现ICollection<T> 接口</typeparam>
        /// <param name="collection">待待充Collection</param>
        /// <param name="tbDesp">Table相关描述信息</param>
        /// <param name="param">填充时所准备的相关参数,包括初始化每一个对象委托,根据相关数据设置相关属性值委托(默认反射)</param>
        /// <returns></returns>
        public string GetCollectionFromTable <T, TCollection>(TCollection collection, TableDescription tbDesp, SpreadGetTableCollectionParams <T> param) where TCollection : ICollection <T>
        {
            tbDesp.NullCheck("tbDesp");
            collection.NullCheck("数据集合不能为空");
            param.ExportRow.NullCheck("exportRow");
            this.CheckTableExists(tbDesp.TableName);

            StringBuilder customLog = new StringBuilder();
            Table         tb        = this.Tables[tbDesp.TableName];
            int           rowIndex  = 0;

            foreach (TableRow tr in tb.Rows)
            {
                ExcportRowContext context = new ExcportRowContext();
                context.RowIndex = rowIndex;
                foreach (TableColumnDescription tc in tbDesp.AllColumns)
                {
                    if (tb.Columns.ContainsKey(tc.ColumnName))
                    {
                        context.PropertyDescriptions.Add(new ExportCellDescription(tc.PropertyName)
                        {
                            TableColumnName = tc.ColumnName, Value = tr[tb.Columns[tc.ColumnName]].Value, Address = CellAddress.Parse(tb.Columns[tc.ColumnName].Position + tb.Address.StartColumn, tr.RowIndex + tb.Address.StartRow + 1).ToString()
                        });
                    }
                }

                ExportRowResult <T> result = param.ExportRow(context);

                if (result.Validated == true && result.CurrentObject != null)
                {
                    collection.Add(result.CurrentObject);
                }

                customLog.Append(result.ErrorLog);
                rowIndex++;

                if (result.Validated == false && param.ValidationOperator == ValidationErrorStopMode.Stop)
                {
                    break;
                }
            }

            return(customLog.ToString());
        }
Exemplo n.º 3
0
        /*	public void GetCollectionFromTable<T, TCollection>(TCollection collection, SpreadGetTableCollectionParams<T> param) where TCollection : ICollection<T>
         * {
         *     this.GetCollectionFromTable<T, TCollection>(SpreadSheetAttributeHelper.GetTableDescription<T>(), collection, param);
         * } */

        public void GetCollectionFromTable <T, TCollection>(TableDescription tbDesp, TCollection collection, SpreadGetTableCollectionParams <T> param) where TCollection : ICollection <T>
        {
            tbDesp.NullCheck("tbDesp");
            collection.NullCheck("数据集合不能为空");
            param.IintObj.NullCheck("创建空实体不能为空");

            this.CheckTableExists(tbDesp.TableName);

            Table tb = this.Tables[tbDesp.TableName];

            foreach (TableRow tr in tb.Rows)
            {
                T data = param.IintObj();
                foreach (TableColumnDescription tc in tbDesp.AllColumns)
                {
                    if (tb.Columns.ContainsKey(tc.ColumnName))
                    {
                        CellBase cell = tr[tb.Columns[tc.ColumnName]];
                        if (param.SetObjProperty != null)
                        {
                            param.SetObjProperty(ref data, cell.Value, tc.ColumnName, tc.PropertyName);
                        }
                        else
                        {
                            SpreadSheetExcportHelper.SetPropertyValue <T>(data, tc.PropertyName, cell.Value);
                        }
                    }
                }
                collection.Add(data);
            }
        }
Exemplo n.º 4
0
 public string GetCollectionFromTable <T, TCollection>(TCollection collection, SpreadGetTableCollectionParams <T> param) where TCollection : ICollection <T>
 {
     return(this.GetCollectionFromTable <T, TCollection>(collection, SpreadSheetAttributeHelper.GetTableDescription <T>(), param));
 }