private void GetSummary() { _sheetDifferences.Clear(); for (int i = 0; i < leftWorkbook.sheetNames.Count; i++) { string sheetName = leftWorkbook.sheetNames[i]; if (rightWorkbook.sheetNames.Contains(sheetName)) { ExcelSheet leftExcelSheet = leftWorkbook.LoadSheet(sheetName); ExcelSheet rightExcelSheet = rightWorkbook.LoadSheet(sheetName); int columnCount = Math.Max(leftExcelSheet.columnCount, rightExcelSheet.columnCount); VSheet leftSheet = new VSheet(leftExcelSheet, columnCount); VSheet rightSheet = new VSheet(rightExcelSheet, columnCount); diff_match_patch comparer = new diff_match_patch(); string leftContent = leftSheet.GetContent(); string rightContent = rightSheet.GetContent(); List <Diff> diffs = comparer.diff_main(leftContent, rightContent, true); comparer.diff_cleanupSemanticLossless(diffs); bool isDifferent = false; for (int diffIndex = 0; diffIndex < diffs.Count; diffIndex++) { if (diffs[diffIndex].operation != Operation.EQUAL) { isDifferent = true; break; } } _sheetDifferences.Add(sheetName, isDifferent); } } }
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; }