private void Copy2Left() { if (rightGrid.SelectedRows.Count > 0) { int firstRowIndex = rightGrid.FirstDisplayedScrollingRowIndex; DataTable table = leftGrid.DataSource as DataTable; List <int> selectionList = new List <int>(); for (int selectionIndex = 0; selectionIndex < rightGrid.SelectedRows.Count; selectionIndex++) { int rowIndex = rightGrid.SelectedRows[selectionIndex].Index; currentSheet.Copy2Left(rowIndex); VRow row = currentSheet.left.GetRow(rowIndex) as VRow; DataRow dataRow = table.Rows[rowIndex]; dataRow.BeginEdit(); for (int i = 0; i < table.Columns.Count; i++) { IExcelCell cell = row.GetCell(i); dataRow[i] = cell != null ? cell.value : string.Empty; } dataRow.EndEdit(); selectionList.Add(rowIndex); } table.AcceptChanges(); rightGrid.FirstDisplayedScrollingRowIndex = firstRowIndex; stopUpdate = true; leftGrid.ClearSelection(); for (int i = 0; i < selectionList.Count; i++) { rightGrid.Rows[selectionList[i]].Cells[0].Selected = true; leftGrid.Rows[selectionList[i]].Cells[0].Selected = true; } stopUpdate = false; } }
public void CopyFrom(IExcelRow other) { VRow row = other as VRow; _targetRowIndex = row.realRowIndex; _columns.Clear(); _changed = true; for (int columnIndex = 0; columnIndex < sheet.columnCount; columnIndex++) { IExcelCell cell = row.GetCell(columnIndex); IExcelCell newCell = null; if (cell == null) { newCell = new ExcelCell(_rowIndex, columnIndex); } else { newCell = new ExcelCell(_rowIndex, columnIndex, cell.cellType, cell.value); } _columns.Add(newCell); } }
public void Save(ISheet sheet) { int realRowIndex = 0; for (int rowIndex = 0; rowIndex < _rows.Count; rowIndex++) { VRow row = _rows[rowIndex] as VRow; if (row.realRowIndex != -1 || row.targetRowIndex != -1) { IRow sheetRow = null; if (row.realRowIndex != -1 && row.changed && row.targetRowIndex == -1) { sheetRow = sheet.GetRow(realRowIndex); if (sheetRow != null) { int lastRowIndex = sheet.LastRowNum; sheet.ShiftRows(realRowIndex + 1, sheet.LastRowNum, -1, true, false); } continue; } if (realRowIndex <= sheet.LastRowNum && row.realRowIndex != -1) { sheetRow = sheet.GetRow(realRowIndex); } else { if (realRowIndex <= sheet.LastRowNum) { sheet.ShiftRows(realRowIndex, sheet.LastRowNum, 1, true, false); } sheetRow = sheet.CreateRow(realRowIndex); //sheetRow = sheet.GetRow(realRowIndex); } int lastCellIndex = sheetRow.LastCellNum; for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) { IExcelCell cell = row.GetCell(columnIndex); ICell sheetCell = sheetRow.GetCell(columnIndex); if (cell != null && cell.value != null) { if (sheetCell == null) { sheetCell = sheetRow.CreateCell(columnIndex); } if (sheetCell != null) { sheetCell.SetCellValue(cell.value); } } else { if (sheetCell != null) { sheetRow.RemoveCell(sheetCell); } } } realRowIndex++; } } }