예제 #1
0
        private void AddRow(int leftRowIndex, int rightRowIndex, bool isDifferent)
        {
            RowComparer newRow = new RowComparer(_rows.Count, leftRowIndex, rightRowIndex, isDifferent);

            _rows.Add(newRow);
            newRow.CompareCells(_columnCount, left, right);
        }
예제 #2
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);
        }
예제 #3
0
        public void Execute(IExcelSheet left, IExcelSheet right, int leftAlignIndex = -1, int rightAlignIndex = -1)
        {
            _isDifferent = false;

            _columnCount = Math.Max(left.columnCount, right.columnCount);
            _left        = new VSheet(left, _columnCount);
            _right       = new VSheet(right, _columnCount);

            _leftAlignIndex  = leftAlignIndex;
            _rightAlignIndex = rightAlignIndex;
            if (_leftAlignIndex != -1 && _rightAlignIndex != -1)
            {
                int beginRow = 0;
                int endRow   = 0;
                if (_leftAlignIndex > _rightAlignIndex)
                {
                    endRow = _leftAlignIndex - 1;
                    ((VSheet)_right).PadRowsAt(_rightAlignIndex, (_leftAlignIndex - _rightAlignIndex));
                }
                else
                {
                    endRow = _rightAlignIndex - 1;
                    ((VSheet)_left).PadRowsAt(_leftAlignIndex, (_rightAlignIndex - _leftAlignIndex));
                }

                leftContent.Clear();
                rightContent.Clear();
                {
                    diff_match_patch comparer     = new diff_match_patch();
                    string           leftContent  = _left.GetContent(beginRow, endRow);
                    string           rightContent = _right.GetContent(beginRow, endRow);
                    List <Diff>      diffs        = comparer.diff_main(leftContent, rightContent, true);
                    comparer.diff_cleanupSemantic(diffs);

                    Compare(diffs, beginRow, beginRow);
                }

                leftContent.Clear();
                rightContent.Clear();
                {
                    endRow++;
                    diff_match_patch comparer     = new diff_match_patch();
                    string           leftContent  = _left.GetContent(endRow, endRow);
                    string           rightContent = _right.GetContent(endRow, endRow);
                    List <Diff>      diffs        = comparer.diff_main(leftContent, rightContent, true);
                    comparer.diff_cleanupSemantic(diffs);

                    Compare(diffs, endRow, endRow);
                }

                leftContent.Clear();
                rightContent.Clear();
                {
                    endRow++;
                    diff_match_patch comparer     = new diff_match_patch();
                    string           leftContent  = _left.GetContent(endRow, _left.rowCount - 1);
                    string           rightContent = _right.GetContent(endRow, _right.rowCount - 1);
                    List <Diff>      diffs        = comparer.diff_main(leftContent, rightContent, true);
                    comparer.diff_cleanupSemantic(diffs);

                    Compare(diffs, endRow, endRow);
                }
            }
            else
            {
                diff_match_patch comparer     = new diff_match_patch();
                string           leftContent  = _left.GetContent();
                string           rightContent = _right.GetContent();
                List <Diff>      diffs        = comparer.diff_main(leftContent, rightContent, true);
                comparer.diff_cleanupSemantic(diffs);

                Compare(diffs, 0, 0);
            }

            VSheet leftResult  = new VSheet(_left.name, _columnCount);
            VSheet rightResult = new VSheet(_right.name, _columnCount);

            List <int> deleteList = new List <int>();

            for (int i = 0; i < _rows.Count; i++)
            {
                RowComparer row      = _rows[i];
                IExcelRow   leftRow  = _left.GetRow(row.leftRowIndex);
                IExcelRow   rightRow = _right.GetRow(row.rightRowIndex);
                if (GetRealRowIndex(leftRow) == -1 && GetRealRowIndex(rightRow) == -1)
                {
                    deleteList.Add(i);
                    continue;
                }
                leftResult.NewRow(leftRow);
                rightResult.NewRow(rightRow);
            }

            for (int i = deleteList.Count - 1; i >= 0; i--)
            {
                _rows.RemoveAt(deleteList[i]);
            }

            _left  = leftResult;
            _right = rightResult;
        }