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

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

            //Merge entire range
            var range = worksheet.Range("A1:B2");
            range.Value = "Merged A1:B2";
            range.Merge();
            range.Style.Alignment.Vertical = AlignmentVerticalValues.Top;
           
            //Merge targe row in the range
            worksheet.Cell("A4").Value = "Merged first row of range(A4:D5)";
            var range2 = worksheet.Range("A4:D5");
            var rowInRange = range2.Row(1);
            rowInRange.Merge();
            rowInRange.Style.Alignment.Horizontal = AlignmentHorizontalValues.Center;
            
            //Merge target column in the range
            var range3 = worksheet.Range("A7:C15");
            var columnInRange = range3.Column(2);
            columnInRange.Merge();
            columnInRange.Value = "Merged second column of Range(A7:C15)";
            columnInRange.Style.Alignment.WrapText = true;

            //Add border to all ranges
            var allMerged = worksheet.Ranges("A1:B2,A4:D5,A7:C15").AddToNamed("MergedRange");
            allMerged.Style.Border.OutsideBorder = BorderStyleValues.Thick;
            allMerged.Style.Border.OutsideBorderColor = ExcelColor.Red;

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