Ejemplo n.º 1
0
        public void Copy2Right(int rowIndex)
        {
            VRow leftRow  = _left.GetRow(rowIndex) as VRow;
            VRow rightRow = _right.GetRow(rowIndex) as VRow;

            rightRow.CopyFrom(leftRow);
            _rows[rowIndex] = new RowComparer(rowIndex, rowIndex, rowIndex, false);
            _rows[rowIndex].CompareCells(_columnCount, left, right);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 增加一个新的行
        /// </summary>
        /// <returns></returns>
        internal VRow NewRow(IExcelRow referenceRow)
        {
            VRow row = new VRow(this, _rows.Count, referenceRow);

            _rows.Add(row);
            if (row.realRowIndex != -1)
            {
                _realRowMap.Add(row.realRowIndex, row);
            }
            return(row);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 根据IExcelSheet构造一个用于对比的VSheet对象
 /// </summary>
 /// <param name="sheet"></param>
 public VSheet(IExcelSheet sheet, int columnCount)
 {
     _name        = sheet.name;
     _columnCount = columnCount;
     for (int i = 0; i < sheet.rowCount; i++)
     {
         VRow row = new VRow(this, i, sheet.GetRow(i));
         _rows.Add(row);
         if (row.realRowIndex != -1)
         {
             _realRowMap.Add(row.realRowIndex, row);
         }
     }
 }
Ejemplo n.º 4
0
        public VRow(VSheet sheet, int rowIndex, IExcelRow referenceRow)
        {
            _sheet    = sheet;
            _rowIndex = rowIndex;

            if (referenceRow != null)
            {
                if (referenceRow is VRow)
                {
                    VRow row = referenceRow as VRow;
                    _realRowIndex   = row.realRowIndex;
                    _targetRowIndex = row.targetRowIndex;
                }
                else
                {
                    ExcelRow row = referenceRow as ExcelRow;
                    _realRowIndex = rowIndex;
                }

                for (int columnIndex = 0; columnIndex < sheet.columnCount; columnIndex++)
                {
                    IExcelCell cell    = referenceRow.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);
                }
            }
            else
            {
                _realRowIndex = -1;
                for (int columnIndex = 0; columnIndex < sheet.columnCount; columnIndex++)
                {
                    _columns.Add(new ExcelCell(_rowIndex, columnIndex));
                }
            }
        }
Ejemplo n.º 5
0
        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;
            }
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        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++;
                }
            }
        }