RhSolutions-AddIn/RhSolutions.AddIn/Tools/WorksheetExtensions.cs

72 lines
1.4 KiB
C#

#if !NET472
using System.Runtime.Versioning;
#endif
namespace RhSolutions.Tools;
#if !NET472
[SupportedOSPlatform("windows")]
#endif
public static class WorksheetExtensions
{
private static readonly Dictionary<string, string> pricelistParameters =
RhSolutionsAddIn.Configuration.GetPriceListHeaders();
public static bool IsValidSource(this Worksheet worksheet)
{
Range headerRow;
string[] fields = pricelistParameters.Values
.Where(v => v != "Прежний материал")
.ToArray();
var value = worksheet.Cells.Find(fields[0]);
if (value == null)
{
return false;
}
else
{
headerRow = value.EntireRow;
}
for (int i = 1; i < fields.Length; i++)
{
if (headerRow.Find(fields[i]) == null)
{
return false;
}
}
return true;
}
public static void AddValue(this Range range, double value)
{
if (range.Value2 == null)
{
range.Value2 = value;
}
else
{
range.Value2 += value;
}
}
public static void AddValue(this Range range, string value)
{
if (range.Value2 == null)
{
range.Value2 = value;
}
else
{
range.Value2 = $"{range.Value2} {value}";
}
}
}