Ejemplo n.º 1
0
        public static Workbook ToExcel <T>(this IEnumerable <T> src) where T : new()
        {
            var myWb = new Workbook();

            myWb.AddStyles();
            var myWs = myWb.Worksheets.Add("one");

            var headerRow = myWs.Table.Rows.Add();
            var cols      = MereUtils.CacheCheck <T>().SelectMereColumns.ToList();

            foreach (var field in cols)
            {
                var myCol = new WorksheetColumn(150);
                myWs.Table.Columns.Add(myCol);
                headerRow.Cells.Add(field.DisplayName, DataType.String, "HeaderStyle");
            }

            foreach (var rec in src)
            {
                var newRow = myWs.Table.Rows.Add();
                newRow.AutoFitHeight = false;
                foreach (var field in cols)
                {
                    var v   = field.GetBase(rec);
                    var val = v == null ? "" : v.ToString();
                    newRow.Cells.Add(val, DataType.String, (myWs.Table.Rows.IndexOf(newRow) % 2) == 0 ? "s31" : "s31Odd");
                }
            }

            return(myWb);
        }