123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System;
- using System.Collections.Generic;
- using System.Linq.Expressions;
- using System.Reflection;
- using System.Text;
- namespace XYY.Core.Standard.ExcelHelper.MSExcelHelper
- {
- public class MSExcelTableMapping : MSExcelClassMapping<System.Data.DataTable>
- {
- }
- public class MSExcelDefaultMapping<T> : MSExcelClassMapping<T>
- {
- }
- public abstract class MSExcelClassMapping<TClass>
- {
- public virtual int[] SheetIndexs(List<string> sheetNames)
- {
- return new int[] { 1 };
- }
- public virtual int RemarkIndex()
- {
- return 0;
- }
- public List<ExcelMappingItem> Items { get; set; } = new List<ExcelMappingItem>();
- public List<ExcelMappingAttrItem> Attrs { get; set; } = new List<ExcelMappingAttrItem>();
- //public List<ExcelMappingItem<TClass> items => new List<ExcelMappingItem>();
- public ExcelMappingItem Map<TMember>(Expression<Func<TClass, TMember>> expression)
- {
- var MappingItem = new ExcelMappingItem();
- if (expression.Body.NodeType == ExpressionType.MemberAccess)
- {
- MemberExpression memberExpression = expression.Body as MemberExpression;
- MappingItem = Map(memberExpression.Member);
- MappingItem.LambdaExpression = expression;
- }
- return MappingItem;
- }
- public ExcelMappingItem Map(MemberInfo memberInfo)
- {
- var MappingItem = new ExcelMappingItem();
- if (memberInfo.MemberType == MemberTypes.Property)
- {
- PropertyInfo propertyInfo = memberInfo as PropertyInfo;
- MappingItem.PropertyInfo = propertyInfo;
- var pt = MappingItem.PropertyInfo.PropertyType;
- MappingItem.ColumnFormattext = ExcelFormattextHelper.GetColumnFormattext(pt);
- Items.Add(MappingItem);
- return MappingItem;
- }
- else
- {
- return MappingItem;
- }
- }
- }
- }
|