using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace iDiTect.Excel.Demo
{
    public static class AutoFilterHelper
    {        
        public static void SingleColumnAutoFilter()
        {
            var workbook = new Workbook();
            var worksheet = workbook.Worksheets.Add("SingleColumnAutoFilter");

            //Add some data to cells
            worksheet.Cell("A1").Value = "Name";
            worksheet.Cell("A2").Value = "Orange";
            worksheet.Cell("A3").Value = "Apple";
            worksheet.Cell("A4").Value = "Banana";
            
            //Apply auto filter to first column
            var filter = worksheet.RangeUsed().Column(1).SetAutoFilter();
            //Add filter like BeginWith or something else
            filter.Column(1).BeginWith("B");

            workbook.Save("SingleColumnAutoFilter.xlsx");
        }

        public static void MultipleColumnsAutoFilter()
        {
            var workbook = new Workbook();
            var worksheet = workbook.Worksheets.Add("MultipleColumnsAutoFilter");

            //Add data to 2 columns
            worksheet.Cell("B1").Value = "Name";
            worksheet.Cell("C1").Value = "Id";

            for (int i = 2; i < 10; i++)
            {
                worksheet.Cell(i, "B").Value = "A" + i;
                worksheet.Cell(i, "C").Value = i;
            }
           
            //Apply auto filter to all used range
            var filter = worksheet.RangeUsed().SetAutoFilter();
            //Add filter to the second data column, here is column C
            //You can add multiple filter rule by Or/And keyword
            filter.Column(2).LessThan(4).Or.GreaterThan(7);

            workbook.Save("MultipleColumnsAutoFilter.xlsx");
        }

        

    }
}
