private Spreadsheet(Dictionary <int, ISpreadsheetRow> rows, ISpreadsheetHeader spreadsheetHeader) { ColumnCount = spreadsheetHeader.ColumnCount; RowCount = rows.Keys.Max() + 1; _spreadsheetHeader = spreadsheetHeader; _emptyRow = new SpreadsheetRow(_spreadsheetHeader, Enumerable.Empty <KeyValuePair <int, string> >()); _rowsByIndex = rows; }
public Spreadsheet(IEnumerable <Cell> cells, IEnumerable <KeyValuePair <int, string> > columnHeaders = null) { columnHeaders = columnHeaders ?? Enumerable.Empty <KeyValuePair <int, string> >(); //TODO: improve performance here RowCount = cells.Max(x => x.Row) + 1; ColumnCount = cells.Select(x => x.Column).Union(columnHeaders.Select(x => x.Key)).Max() + 1; _spreadsheetHeader = new SpreadsheetHeader(ColumnCount, columnHeaders); _emptyRow = new SpreadsheetRow(_spreadsheetHeader, Enumerable.Empty <KeyValuePair <int, string> >()); _rowsByIndex = cells.GroupBy(x => x.Row) .ToDictionary( x => x.Key, x => (ISpreadsheetRow) new SpreadsheetRow(_spreadsheetHeader, x.Select(y => new KeyValuePair <int, string>(y.Column, y.Value)))); }
private SpreadsheetRow(ISpreadsheetHeader spreadsheetHeader, Dictionary <int, string> valuesColumnIndex) { ColumnCount = spreadsheetHeader.ColumnCount; _byColumnIndex = valuesColumnIndex; _spreadsheetHeader = spreadsheetHeader; }
public ISpreadsheetRow CloneWithOtherHeader(ISpreadsheetHeader spreadsheetHeader) { return(new SpreadsheetRow(spreadsheetHeader, _byColumnIndex)); }
public SpreadsheetRow(ISpreadsheetHeader spreadsheetHeader, IEnumerable <KeyValuePair <int, string> > cells) : this(spreadsheetHeader, cells.ToDictionary(x => x.Key, x => x.Value)) { }