public byte[] GenerateReport(List <object> itemList, GridConfigurationBase gridConfig) { List <GridColumnBase> columnList = gridConfig.GridColumnBases.Where(x => !x.KeyColumn).ToList(); this.Columns = GetColumns(columnList.Count()); using (var workbook = new XLWorkbook()) { IXLWorksheet ws = workbook.Worksheets.Add("Info General"); CreateHeader(columnList, ws); foreach (object obj in itemList) { int file = itemList.IndexOf(obj) + 2; foreach (GridColumnBase cName in columnList) { int column = columnList.IndexOf(cName); var value = GridColumnBase.GetKeyValue(obj, cName.PropertyInfo); ws.Cell($"{Columns[column]}{file}") .Value = value; } } ws.Columns().AdjustToContents(); using (var ms = new MemoryStream()) { workbook.SaveAs(ms); return(ms.ToArray()); } } }
public async Task CreateGridSearch(GridColumnBase gridColumn, List <string> options) { SearchSelect = options; SearchProperty = gridColumn.PropertyInfo; SearchPropName = gridColumn.Name; SearchText = ""; SearchPropType = await Task.Run(() => GetSearchPropertyType(gridColumn)); DialogOpen = true; }
public CellContexMenuOption(GridColumnBase gridColumn, object context, string urlFolder) { GridColumn = gridColumn; RowValues = context; OneItemList = new List <object>(); OneItemList.Add(RowValues); string keyValue = GridColumnBase.GetKeyValue(context, context.GetType().GetProperty(gridColumn.KeyColumnName)).ToString(); gridColumn.InitializeContextMenuOptions(keyValue, urlFolder); }
private PropertyType GetSearchPropertyType(GridColumnBase gridColumn) { if (SearchProperty != null) { PropertyType searchType = gridColumn.PropertyType; if (searchType != PropertyType.datetime && SearchSelect != null && SearchSelect.Any()) { SearchText = SearchSelect.OrderBy(x => x).FirstOrDefault(); searchType = PropertyType.list; } return(searchType); } return(PropertyType.noType); }
private XLDataType GetDataType(GridColumnBase gridColumn) { PropertyType propertyType = gridColumn.PropertyType; switch (propertyType) { case PropertyType.number: return(XLDataType.Number); case PropertyType.datetime: return(XLDataType.DateTime); default: return(XLDataType.Text); } }
private static string GetColumnsNames(List <GridColumnBase> columnList, System.Data.DataTable dataResult, IXLRow row) { string readRange = string.Format("{0}:{1}", 1, row.LastCellUsed().Address.ColumnNumber); foreach (IXLCell cell in row.Cells(readRange)) { GridColumnBase gridColumn = columnList.FirstOrDefault(x => x.Name == cell.Value.ToString()); if (gridColumn != null) { var columName = gridColumn.PropertyInfo.Name; dataResult.Columns.Add(columName); } else { throw new System.Exception($"Column Name {cell.Value.ToString()} does not match any property in object"); } } return(readRange); }