예제 #1
0
        public IXLWorksheet Export <T>(IXLWorksheet sheet, List <T> list) where T : CxFile
        {
            ExportTemplate(sheet, list.First());

            var props  = list.First().GetType().GetProperties();
            var rownum = 2;

            foreach (var model in list)
            {
                for (int i = 0; i < props.Count(); i++)
                {
                    var spec = (CxColSpec)props[i].GetCustomAttributes(true)
                               .Where(x => x is CxColSpec)?.FirstOrDefault();

                    if (spec == null)
                    {
                        continue;
                    }

                    var colrow = spec.Col + rownum;
                    sheet.CLSetContent(colrow, model.GetType().GetProperty(props[i].Name).GetValue(model, null));
                }
                rownum++;
            }
            sheet.CLSetDefaultHeight();
            return(sheet);
        }