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

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

            //Set Page Orientation
            worksheet.PageSetup.PageOrientation = PageOrientation.Portrait;

            //Set Scaling, you can choose set "Adjust to", or "Fit to"
            //Set Adjust to: X percentage of normal size
            worksheet.PageSetup.AdjustTo(90);
            //Or set Fit to: X page(s) wide by Y tall
            //worksheet.PageSetup.PagesWide = 1;
            //worksheet.PageSetup.PagesTall = 2;

            //Set Paper size
            worksheet.PageSetup.PaperSize = PaperSize.A4Paper;

            //Set Print quality
            worksheet.PageSetup.HorizontalDpi = 300;
            worksheet.PageSetup.VerticalDpi = 300;

            //Set First page number
            worksheet.PageSetup.FirstPageNumber = 1;

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

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

            //Set margins
            worksheet.PageSetup.Margins.Top = 2;
            worksheet.PageSetup.Margins.Bottom = 0.2;
            worksheet.PageSetup.Margins.Left = 1.5;
            worksheet.PageSetup.Margins.Right = 0.5;            
            worksheet.PageSetup.Margins.Header = 1.3;
            worksheet.PageSetup.Margins.Footer = 0.3;

            //Set Center on page
            worksheet.PageSetup.CenterHorizontally = true;
            worksheet.PageSetup.CenterVertically = false;

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

        public static void HeaderFooterInPrint()
        {
            var workbook = new Workbook();
            var worksheet = workbook.Worksheets.Add("HeaderFooterInPrint");
            
            //Set Header
            //Add predefined text to header left, choose to only show on the first page
            worksheet.PageSetup.Header.Left.AddText(HeaderFooterPredefinedText.Date, HeaderFooterOccurrence.FirstPage);
            //Add text to header right, choose to show on all pages
            worksheet.PageSetup.Header.Right.AddText("Page ", HeaderFooterOccurrence.AllPages);
            //Add predefined text, default is showing on all pages
            worksheet.PageSetup.Header.Right.AddText(HeaderFooterPredefinedText.PageNumber);

            //Set Footer
            //Add text to footer center, choose to show on even pages
            worksheet.PageSetup.Footer.Center.AddText("Footer color is ", HeaderFooterOccurrence.EvenPages);
            //Add text to footer, and change text tyle, like font color, font size, bold or italic
            var richString = worksheet.PageSetup.Footer.Center.AddText("Red", HeaderFooterOccurrence.EvenPages);
            richString.FontColor = ExcelColor.Red;

            //Set Scale with document
            worksheet.PageSetup.ScaleWithDocument = true;

            //Set Align with page margins
            worksheet.PageSetup.AlignWithPageMargins = true;

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

        public static void SheetInPrint()
        {
            var workbook = new Workbook();
            var worksheet = workbook.Worksheets.Add("SheetInPrint");
            
            //Set Print area
            worksheet.PageSetup.PrintAreas.Add("A1:F10");
            
            //Set Gridlins
            worksheet.PageSetup.ShowGridlines = true;

            //Set Black and white
            worksheet.PageSetup.BlackAndWhite = false;

            //Set Draft guality
            worksheet.PageSetup.DraftQuality = false;

            //Set Row and column headings
            worksheet.PageSetup.ShowRowAndColumnHeadings = true;

            //Set Comment
            worksheet.PageSetup.ShowComments = ShowCommentsValues.AtEnd;

            //Set Cell errors as
            worksheet.PageSetup.PrintErrorValue = PrintErrorValues.NA;

            //Set Page order
            worksheet.PageSetup.PageOrder = PageOrderValues.DownThenOver;
            
            workbook.Save("SheetInPrint.xlsx");
        }

    }
}
