Пример #1
0
        /// <summary>
        /// Binds the specified column name (table header) in excel to the class property.
        /// </summary>
        /// <typeparam name="TProperty">The type of the property.</typeparam>
        /// <param name="columnNameInExcel">The column name (table header) in excel.</param>
        /// <param name="expression">The property expression.</param>
        /// <param name="isMandatory">If set to <c>true</c> - this property is mandatory and the reading will stop on the row where the cell specified by this property is empty, even if other cells still have values.</param>
        public void Bind <TProperty>(string columnNameInExcel, Expression <Func <TModel, TProperty> > expression, bool isMandatory = false)
        {
            var name = string.Empty;

            var body = expression.Body as MemberExpression;

            while (body != null && body.NodeType == ExpressionType.MemberAccess)
            {
                if (name.Length > 0)
                {
                    name = body.Member.Name + "." + name;
                }
                else
                {
                    name = body.Member.Name;
                }

                body = body.Expression as MemberExpression;
            }

            // var columnProperty = (expression.Body as MemberExpression).Member as PropertyInfo;
            var propertyData = new ColumnPropertyData
            {
                ExcelColumnName = columnNameInExcel,
                PropertyName    = name,
                IsMandatory     = isMandatory
            };

            this.tableColumnBuilder.columnProperties.Add(propertyData);
        }
Пример #2
0
        public void IndexConverter_A()
        {
            var index = ColumnPropertyData.GetColumnIndexFromCellAddress("A");

            index.ShouldBe(1);
        }
Пример #3
0
        public void IndexConverterRow_XFEWithRow()
        {
            var index = ColumnPropertyData.GetRowIndexFromCellAddress("XFE234");

            index.ShouldBe(234);
        }
Пример #4
0
        public void IndexConverter_XFE()
        {
            var index = ColumnPropertyData.GetColumnIndexFromCellAddress("XFE");

            index.ShouldBe(16385);
        }
Пример #5
0
        public void IndexConverter_PC()
        {
            var index = ColumnPropertyData.GetColumnIndexFromCellAddress("PC");

            index.ShouldBe(419);
        }
Пример #6
0
        public void IndexConverter_IVWithRow()
        {
            var index = ColumnPropertyData.GetColumnIndexFromCellAddress("IV22334");

            index.ShouldBe(256);
        }