Example #1
0
        /// <summary>
        /// 导出类型的属性名
        /// </summary>
        /// <returns></returns>
        protected string[] GetHeadNames()
        {
            if (TableHeads != null && TableHeads.Count() > 0)
            {
                return(TableHeads.ToArray());
            }

            int pcount = propertyInfoes.Length;

            string[] names = new string[pcount];
            int      i     = 0;

            for (; i < pcount; i++)
            {
                PropertyInfo            p  = propertyInfoes[i];
                DisplayOpenXmlAttribute da = p.GetCustomAttributes(typeof(DisplayOpenXmlAttribute), false).FirstOrDefault() as DisplayOpenXmlAttribute;
                if (da != null)
                {
                    names[i] = da.Name;
                }
                else
                {
                    names[i] = p.Name;
                }
            }
            return(names);
        }
Example #2
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="type">属性类型</param>
 /// <param name="displayOpenXmlAttr"><see cref="DisplayOpenXmlAttribute"/></param>
 public PropertyDto(Type type, DisplayOpenXmlAttribute displayOpenXmlAttr)
 {
     _type               = type;
     _typeCodeValue      = TypeUtil.GetTypeCode(_type);
     _cellType           = GetCellValues(_typeCodeValue);
     _displayOpenXmlAttr = displayOpenXmlAttr;
 }
Example #3
0
        /// <summary>
        /// 确定属性信息
        /// </summary>
        /// <param name="sheetData"><see cref="SheetData"/>对象</param>
        /// <returns><see cref="PropertyDto"/>对象数组</returns>
        private PropertyDto[] GetPropertyDtos(SheetData sheetData)
        {
            int  pcount = propertyInfoes.Length;
            uint i      = 0;

            PropertyDto[] pds = new PropertyDto[pcount];
            for (; i < pcount; i++)
            {
                PropertyInfo            pi         = propertyInfoes[i];
                DisplayOpenXmlAttribute displayAtt = pi.GetCustomAttributes(typeof(DisplayOpenXmlAttribute), false).FirstOrDefault() as DisplayOpenXmlAttribute;
                PropertyDto             pd         = new PropertyDto(pi.PropertyType, displayAtt);
                pd.ColumnReference = CellReferenceUtil.GetColumnReference(i);
                pds[i]             = pd;
            }

            // 使用模板并且使用最后一行的样式
            if (UseTemplate && TemplateUseLastRowStyle)
            {
                // 最后一行
                Row rl = sheetData.LastChild as Row;
                if (rl != null)
                {
                    IEnumerable <Cell>        cls = rl.Elements <Cell>().Where(x => false == string.IsNullOrEmpty(x.CellReference));
                    Dictionary <int, CellDto> dic = cls.Select(x => new CellDto(x.CellReference, x.StyleIndex)).ToDictionary(x => x.ColumnIndex);
                    if (dic.Count() > 0)
                    {
                        int j = 0;
                        for (; j < pcount; j++)
                        {
                            PropertyDto pd = pds[j];
                            CellDto     cd = null;
                            bool        s  = dic.TryGetValue(j, out cd);
                            if (true == s && cd != null)
                            {
                                pd.StyleIndex = (int)cd.StyleIndex;
                            }
                        }
                    }
                }
            }
            return(pds);
        }