/// <summary> /// Adds a Cell to this Row. /// </summary> /// <param name="cell">The Cell to add to this Row</param> public void AddCell(Cell cell) { ushort cCol = cell.Column; if (CellExists(cCol)) throw new Exception(string.Format("Cell already exists at column {0}", cCol)); if (cCol < 1 || cCol > 256) throw new ArgumentOutOfRangeException(string.Format("cell.Col {0} must be between 1 and 256", cCol)); if (_minCellCol == 0) { _minCellCol = cCol; _maxCellCol = cCol; } else { if (cCol < _minCellCol) _minCellCol = cCol; else if (cCol > _maxCellCol) _maxCellCol = cCol; } _cells.Add(cCol, cell); }
internal Cell Add(ushort cellRow, ushort cellColumn) { Cell cell = new Cell(_worksheet); bool haveCell = false; if (cellColumn < 1) throw new ArgumentOutOfRangeException("cellColumn", string.Format("{0} must be >= 1", cellColumn)); else if (cellColumn > BIFF8.MaxCols) throw new ArgumentOutOfRangeException("cellColumn", string.Format("{0} cellColumn must be <= {1}", cellColumn, BIFF8.MaxCols)); if (cellRow < 1) throw new ArgumentOutOfRangeException("cellRow", string.Format("{0} must be >= 1", cellColumn)); else if (cellRow > BIFF8.MaxRows) throw new ArgumentOutOfRangeException("cellRow", string.Format("{0} cellRow must be <= {1}", cellRow, BIFF8.MaxRows)); if (_worksheet.Rows.RowExists(cellRow)) { if (_worksheet.Rows[cellRow].CellExists(cellColumn)) { cell = _worksheet.Rows[cellRow].CellAtCol(cellColumn); haveCell = true; } } else _worksheet.Rows.AddRow(cellRow); if (haveCell) return cell; cell.Coordinate = new CellCoordinate(cellRow, cellColumn); if (_minRow == 0) { _minRow = cellRow; _minCol = cellColumn; _maxRow = cellRow; _maxCol = cellColumn; } else { if (cellRow < _minRow) _minRow = cellRow; else if (cellRow > _maxRow) _maxRow = cellRow; if (cellColumn < _minCol) _minCol = cellColumn; else if (cellColumn > _maxCol) _maxCol = cellColumn; } _worksheet.Rows[cellRow].AddCell(cell); _cellCount++; return cell; }
private void AddCells(Record record) { Bytes bytes = record.Data; ushort rowIndex = bytes.Get(0, 2).GetBits().ToUInt16(); ushort colIndex = bytes.Get(2, 2).GetBits().ToUInt16(); ushort lastColIndex = colIndex; ushort offset = 4; byte[] rid = record.RID; bool isMulti = false; if (rid == RID.MULBLANK) { isMulti = true; rid = RID.BLANK; } else if (rid == RID.MULRK) { isMulti = true; rid = RID.RK; } if (isMulti) { lastColIndex = bytes.Get(bytes.Length - 2, 2).GetBits().ToUInt16(); } while (colIndex <= lastColIndex) { Cell cell = Cells.Add((ushort)(rowIndex + 1), (ushort)(colIndex + 1)); ushort xfIndex = bytes.Get(offset, 2).GetBits().ToUInt16(); offset += 2; Bytes data; if (rid == RID.BLANK) { data = new Bytes(); } else if (rid == RID.RK) { data = bytes.Get(offset, 4); offset += 4; cell.SetValue(rid, data); } else { data = bytes.Get(offset, bytes.Length - offset); if (rid == RID.FORMULA) { FormulaRecord formulaRecord = record as FormulaRecord; cell.SetFormula(data, formulaRecord.StringRecord); } else { cell.SetValue(rid, data); } } colIndex++; } }