Color tab if the sheet contains a changed cell in ExcelComparer

This commit is contained in:
Daniel Schick 2026-01-26 14:45:59 +01:00
parent d02cb0d56b
commit 77c0491aa1

View File

@ -55,8 +55,7 @@ namespace ENI2.Excel
using (var sourceStream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var sourceStream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (var sourceWorkbook = new XLWorkbook(sourceStream)) using (var sourceWorkbook = new XLWorkbook(sourceStream))
using (var comparisonStream = new FileStream(comparisonFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var comparisonWorkbook = new XLWorkbook(comparisonFileName))
using (var comparisonWorkbook = new XLWorkbook(comparisonStream))
{ {
// Es werden Zellen der "used range" miteinander verglichen // Es werden Zellen der "used range" miteinander verglichen
foreach (var sourceSheet in sourceWorkbook.Worksheets) foreach (var sourceSheet in sourceWorkbook.Worksheets)
@ -78,6 +77,7 @@ namespace ENI2.Excel
{ {
int maxRows = Math.Max(sourceRows, targetRows); int maxRows = Math.Max(sourceRows, targetRows);
int maxCols = Math.Max(sourceCols, targetCols); int maxCols = Math.Max(sourceCols, targetCols);
bool sheetHasDiffs = false;
for (int rowidx = 1; rowidx <= maxRows; rowidx++) for (int rowidx = 1; rowidx <= maxRows; rowidx++)
{ {
@ -113,6 +113,7 @@ namespace ENI2.Excel
var cellToHighlight = targetSheet.Cell(rowidx, colidx); var cellToHighlight = targetSheet.Cell(rowidx, colidx);
cellToHighlight.Style.Fill.BackgroundColor = diffColor; cellToHighlight.Style.Fill.BackgroundColor = diffColor;
counter++; counter++;
sheetHasDiffs = true;
} }
} }
else if (targetText == null) else if (targetText == null)
@ -122,6 +123,7 @@ namespace ENI2.Excel
var cellToHighlight = targetSheet.Cell(rowidx, colidx); var cellToHighlight = targetSheet.Cell(rowidx, colidx);
cellToHighlight.Style.Fill.BackgroundColor = diffColor; cellToHighlight.Style.Fill.BackgroundColor = diffColor;
counter++; counter++;
sheetHasDiffs = true;
} }
} }
else if ((sourceText != null) && (targetText != null)) else if ((sourceText != null) && (targetText != null))
@ -131,10 +133,16 @@ namespace ENI2.Excel
var cellToHighlight = targetSheet.Cell(rowidx, colidx); var cellToHighlight = targetSheet.Cell(rowidx, colidx);
cellToHighlight.Style.Fill.BackgroundColor = diffColor; cellToHighlight.Style.Fill.BackgroundColor = diffColor;
counter++; counter++;
sheetHasDiffs = true;
} }
} }
} }
} }
if (sheetHasDiffs)
{
targetSheet.SetTabColor(diffColor);
}
} }
else else
{ {