public ITablePart GetTablePart(IRectangle rectangle) { var excelReferenceToCell = internalTable .GetSortedCellsInRange(new ExcelCellIndex(rectangle.UpperLeft.CellReference), new ExcelCellIndex(rectangle.LowerRight.CellReference)) .Select(cell => new ExcelCell(cell)) .ToDictionary(cell => cell.CellPosition.CellReference); var subTableSize = rectangle.Size; var subTable = JaggedArrayHelper.CreateJaggedArray <ICell[][]>(subTableSize.Height, subTableSize.Width); for (var x = rectangle.UpperLeft.ColumnIndex; x <= rectangle.LowerRight.ColumnIndex; ++x) { for (var y = rectangle.UpperLeft.RowIndex; y <= rectangle.LowerRight.RowIndex; ++y) { if (!excelReferenceToCell.TryGetValue(new CellPosition(y, x).CellReference, out var cell)) { cell = new ExcelCell(internalTable.InsertCell(new ExcelCellIndex(y, x))); } subTable[y - rectangle.UpperLeft.RowIndex][x - rectangle.UpperLeft.ColumnIndex] = cell; } } return(new ExcelTablePart(subTable)); }
public FakeTable(int width, int height) { this.width = width; this.height = height; cells = JaggedArrayHelper.CreateJaggedArray <ICell[][]>(height, width); mergedCells = new List <IRectangle>(); }
public ITablePart GetTablePart(IRectangle rectangle) { if (OutOfBounds(rectangle.UpperLeft) || OutOfBounds(rectangle.LowerRight)) { return(null); } var subTableSize = rectangle.Size; var subTable = JaggedArrayHelper.CreateJaggedArray <ICell[][]>(subTableSize.Height, subTableSize.Width); for (var y = 0; y < subTableSize.Height; ++y) { for (var x = 0; x < subTableSize.Width; ++x) { var sourceCell = cells[rectangle.UpperLeft.RowIndex + y - 1][rectangle.UpperLeft.ColumnIndex + x - 1]; subTable[y][x] = sourceCell ?? new FakeCell(new CellPosition(y + 1, x + 1)); } } return(new FakeTablePart(subTable)); }