Ejemplo n.º 1
0
        /// <summary>
        /// Returns a cell at a given row, column.
        /// It creates a new cell if it does not exist.
        /// It will return the cell if it already exists
        /// </summary>
        /// <param name="rowNumber">Row Number</param>
        /// <param name="columnIndex">Column Index</param>
        /// <returns></returns>
        private Cell GetCell(int rowNumber, int columnIndex)
        {
            string reference = Utilities.BuildReference(rowNumber, columnIndex);
            var    row       = AllCells.FirstOrDefault(c => c.Key == rowNumber).Value;

            // Check if the cell already exists
            var cell = row == null ? null : row.FirstOrDefault(c => c.ColumnNumber == columnIndex);

            // Cell does not exist. Create one.
            if (cell == null)
            {
                cell = new Cell(reference)
                {
                    Stylesheet = _styleSheet
                };

                var currentRow = Rows.FirstOrDefault(r => r.Index == rowNumber);

                // If the row already exists, get the row. Else, create a new row
                List <Cell> thisRow = null;
                if (AllCells.ContainsKey(rowNumber))
                {
                    thisRow = AllCells[rowNumber];
                }
                else
                {
                    thisRow = new List <Cell>();
                    AllCells.Add(rowNumber, thisRow);
                }

                // Add cell to the current row.
                thisRow.Add(cell);

                // Add the current row to the list of rows if it does not exist in the list.
                if (currentRow == null)
                {
                    cell.Row = new Row(rowNumber);
                    Rows.Add(cell.Row);
                }
                else
                {
                    cell.Row = currentRow;
                }

                // Add the current column to the list of columns if it does not exist in the list.
                if (!Columns.ColumnsList.Any(c => c.Index == columnIndex))
                {
                    Columns.ColumnsList.Add(new Column {
                        Index = columnIndex
                    });
                }
            }

            return(cell);
        }
Ejemplo n.º 2
0
        private ICell AddCell(int colIndex, int rowIndex, int colNum, int rowNum, string colName, string rowName)
        {
            var cell = (Cell)AllCells.FirstOrDefault(c => c.ColumnNum == colNum && c.RowNum == rowNum);

            if (cell != null)
            {
                return(cell.UpdateData(colName, rowName));
            }
            cell = new Cell(colNum, rowNum, colName, rowName, CellLocatorTemplate, this, colIndex, rowIndex);
            cell.SetAvatar((GetElementModule)cell.Get().Avatar);

            if (Cache)
            {
                AllCells.Add(cell);
            }
            return(cell);
        }