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

72 lines
1.4 KiB
C#
Raw Normal View History

2023-04-06 08:29:39 +03:00
#if !NET472
using System.Runtime.Versioning;
#endif
2023-04-01 15:24:04 +03:00
2023-04-06 16:40:00 +03:00
namespace RhSolutions.Tools;
2023-04-06 08:29:39 +03:00
#if !NET472
[SupportedOSPlatform("windows")]
#endif
2023-03-28 10:36:36 +03:00
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;
}
2023-03-28 10:36:36 +03:00
public static void AddValue(this Range range, double value)
{
if (range.Value2 == null)
{
range.Value2 = value;
}
2022-02-08 16:19:49 +03:00
2023-03-28 10:36:36 +03:00
else
2022-02-08 16:19:49 +03:00
{
2023-03-28 10:36:36 +03:00
range.Value2 += value;
2022-02-08 16:19:49 +03:00
}
}
2023-05-18 15:26:38 +03:00
public static void AddValue(this Range range, string value)
{
if (range.Value2 == null)
{
range.Value2 = value;
}
else
{
range.Value2 = $"{range.Value2} {value}";
}
}
}