51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
|
#if !NET472
|
|||
|
using System.Runtime.Versioning;
|
|||
|
#endif
|
|||
|
|
|||
|
namespace RhSolutions.Services;
|
|||
|
|
|||
|
public static class WorksheetValidator
|
|||
|
{
|
|||
|
public static Dictionary<string, Range> HeaderCells { get; private set; }
|
|||
|
|
|||
|
public static void Validate(this Worksheet worksheet)
|
|||
|
{
|
|||
|
Range headerRow = null;
|
|||
|
HeaderCells = new();
|
|||
|
var headers = RhSolutionsAddIn.Configuration.GetPriceListHeaders();
|
|||
|
|
|||
|
foreach (var kvp in headers)
|
|||
|
{
|
|||
|
Range cell;
|
|||
|
|
|||
|
if (headerRow == null)
|
|||
|
{
|
|||
|
cell = worksheet.Cells.Find(kvp.Value);
|
|||
|
if (cell == null)
|
|||
|
{
|
|||
|
continue;
|
|||
|
}
|
|||
|
headerRow = cell.EntireRow;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
cell = headerRow.Cells.Find(kvp.Value);
|
|||
|
}
|
|||
|
|
|||
|
if (HeaderCells.ContainsKey(kvp.Key))
|
|||
|
{
|
|||
|
HeaderCells[kvp.Key] = cell;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
HeaderCells.Add(kvp.Key, cell);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static bool IsValid()
|
|||
|
{
|
|||
|
return HeaderCells.Count >= RhSolutionsAddIn.Configuration.GetPriceListHeaders().Count - 1;
|
|||
|
}
|
|||
|
}
|