static ImportExportOptions InitDefaultOptions() { var options = new ImportExportOptions(); options.DefaultHeaderStyle = new CellStyle { Fill = new CellFill { Pattern = FillPattern.Solid, Foreground = new Color(255, 0x46, 0x82, 0xB4) }, Font = new CellFont { Color = new Color(255, 255, 255, 255), Bold = true } }; return(options); }
public static TableInfo <T> Build(ImportExportOptions options = null) { if (options == null) { options = ImportExportOptions.Default; } var type = typeof(T); var properties = type.GetProperties(); var result = new TableInfo <T> { Columns = new List <ColumnInfo <T> >() }; foreach (var p in properties) { var prop = p; var c = new ColumnInfo <T> { Name = prop.Name, Getter = prop.CanRead ? (row) => { return(prop.GetValue(row, null)); } : (Func <T, object>)null, Setter = prop.CanWrite ? (row, value) => { prop.SetValue(row, value, null); } : (Action <T, object>)null, ExportConverter = GetExportConverter(prop.PropertyType), ImportConverter = GetImportConverter(prop.PropertyType) }; if (options.DefaultColumnFormatter != null) { c.ExportColumnFormatter = options.DefaultColumnFormatter(prop.PropertyType); } if (options.DefaultHeaderStyle != null) { c.HeaderStyle = options.DefaultHeaderStyle.Clone(); } result.Columns.Add(c); } return(result); }