aboutsummaryrefslogtreecommitdiff
path: root/src/AddIn/WorksheetExtensions.cs
blob: 7880b66d887f39bbec48aa2356c1e42bf3ffe6b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Microsoft.Office.Interop.Excel;
using RehauSku.PriceListTools;
using System.Linq;

namespace RehauSku
{
    public static class WorksheetExtensions
    {
        public static bool IsRehauSource(this Worksheet worksheet)
        {
            Range amountCell;
            Range skuCell;
            Range groupCell;
            Range nameCell;

            Range[] cells = new[]
            {
                amountCell = worksheet.Cells.Find(PriceListHeaders.Amount),
                skuCell = worksheet.Cells.Find(PriceListHeaders.Sku),
                groupCell = worksheet.Cells.Find(PriceListHeaders.Group),
                nameCell = worksheet.Cells.Find(PriceListHeaders.Name)
            };

            return cells.All(x => x != null);
        }

        public static void AddValue(this Range range, double value)
        {
            if (range.Value2 == null)
            {
                range.Value2 = value;
            }

            else
            {
                range.Value2 += value;
            }
        }
    }
}