private static void PopulateData <T>(ExcelWorksheet worksheet, IList <Column <T> > columns, IList <T> data, int startRow, int startColumn) { for (int i = 0; i < data.Count; ++i) { // Get data item for this row. T dataItem = data[i]; for (int c = 0; c < columns.Count; ++c) { Column <T> column = columns[c]; // Get current cell. ExcelRange cell = worksheet.Cells[startRow + i, startColumn + c]; // Get data for the cell. var expandoObject = dataItem as ExpandoObject; var cellData = expandoObject != null ? new CellData(expandoObject.First(propery => propery.Key == column.HeaderText).Value) : column.GetValueMethod(dataItem); if (cellData.Type == CellType.Image) { // Row is always 1-based, not 0-based. int row = i + (startRow - 1); worksheet.AddImage((byte[])cellData.Value, row, columns.Count); } else { cell.SetValue(cellData); } } } }