/// <summary> /// 移除一个单元格 /// </summary> /// <param name="cell">单元格对象</param> public void Remove(ExcelCell cell) { if (_list.Contains(cell)) { _list.Remove(cell); } }
/// <summary> /// 创建一个新的行对象 /// </summary> /// <returns></returns> public ExcelRow NewRow() { ExcelRow row = new ExcelRow(); foreach (ExcelColumn column in _columns) { ExcelCell cell = new ExcelCell(); cell.OwningColumnInternal = column; cell.OwningRowInternal = row; row.Cells.Add(cell); } return(row); }
/// <summary> /// 新增一个行对象 /// </summary> /// <param name="values">行中的单元格的值</param> public void AddRow(object[] values) { if (values.Length != Columns.Count) { throw new ArgumentOutOfRangeException("values的长度与列数不相等。"); } ExcelRow row = new ExcelRow(); for (int i = 0; i < Columns.Count; i++) { ExcelCell cell = new ExcelCell(); cell.OwningColumnInternal = Columns[i]; cell.Value = values[i]; cell.OwningRowInternal = row; row.Cells.Add(cell); } Rows.Add(row); }
private void ChangeExcelCell(int index, bool isAdd) { if (index >= 0 && index < _list.Count) { if (this[0].ExcelTable != null) { foreach (ExcelRow row in this[index].ExcelTable.Rows) { if (isAdd) { ExcelCell cell = new ExcelCell(); cell.OwningRowInternal = row; cell.OwningColumnInternal = this[index]; row.Cells.Add(cell); } else { row.Cells.RemoveAt(index); } } } } }
/// <summary> /// 新增一个单元格对象 /// </summary> /// <param name="cell">单元格对象</param> public void Add(ExcelCell cell) { _list.Add(cell); }