From e8a4fcb227d7737b653bbd5e7ac2abe75d482904 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Tue, 28 Jun 2022 11:04:44 +0200 Subject: [PATCH] Excel Vergleich Umbau Teil 1 --- ENI2/Excel/ExcelComparer.cs | 34 ++++++++++++++++++++++++---- bsmd.database/ValidationAttribute.cs | 2 +- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/ENI2/Excel/ExcelComparer.cs b/ENI2/Excel/ExcelComparer.cs index 9d93436c..4d9b36e9 100644 --- a/ENI2/Excel/ExcelComparer.cs +++ b/ENI2/Excel/ExcelComparer.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; +using Microsoft.Office.Interop.Excel; namespace ENI2.Excel { @@ -22,6 +23,25 @@ namespace ENI2.Excel { private static int diffColor = ColorTranslator.ToOle(Color.FromArgb(150, 150, 255)); // blue + private static bool GetSheetRange(Worksheet sheet, out int lastUsedRow, out int lastUsedColumn) + { + try + { + Range last = sheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell, Type.Missing); + Range range = sheet.get_Range("A1", last); + + lastUsedRow = last.Row; + lastUsedColumn = last.Column; + return true; + } + catch(Exception) + { + lastUsedColumn = 0; + lastUsedRow = 0; + return false; + } + } + public static string Compare(string sourcePath, string targetPath, out string errorMessage) { string fileName = Path.GetTempPath() + Guid.NewGuid().ToString() + ".xlsx"; @@ -34,18 +54,19 @@ namespace ENI2.Excel ExcelReader source = new ExcelReader(sourcePath); ExcelReader comparison = new ExcelReader(fileName, false); + /* // loop through named cells foreach (string name in comparison.NameDict.Keys) { if (!source.NameDict.ContainsKey(name)) continue; string sourceText = source.ReadText(name); - string targetText = comparison.ReadText(name); + string targetText = comparison.ReadText(name); if (sourceText == null) { if (targetText != null) { - comparison.Colorize(name, diffColor); + comparison.Colorize(name, diffColor); counter++; } } @@ -53,7 +74,7 @@ namespace ENI2.Excel { if (sourceText != null) { - comparison.Colorize(name, diffColor); + comparison.Colorize(name, diffColor); counter++; } } @@ -62,11 +83,14 @@ namespace ENI2.Excel if (!sourceText.Equals(targetText)) { // turn cell blue - comparison.Colorize(name, diffColor); + comparison.Colorize(name, diffColor); counter++; } - } + } } + */ + + comparison.Save(fileName); errorMessage = string.Format("{0} differences found", counter); } diff --git a/bsmd.database/ValidationAttribute.cs b/bsmd.database/ValidationAttribute.cs index 0e531cf2..16fa8ff4 100644 --- a/bsmd.database/ValidationAttribute.cs +++ b/bsmd.database/ValidationAttribute.cs @@ -42,7 +42,7 @@ namespace bsmd.database STRING_UNNUMBER = 23, STRING_IMOCLASS = 24, DRAUGHT_IMPLAUSIBLE = 25, - TIME_IMPLAUSIBLE = 26, + TIME_IMPLAUSIBLE = 26, PORTAREA, TRUNCATE = 28, MMSI = 29,