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

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

            //Input cell value by row and column coordinate
            worksheet.Cell(1, 1).Value = "A1";

            //Input cell value by cell name
            worksheet.Cell("B1").Value = "B1";

            //Input cell value by row id and column name
            worksheet.Cell(1, "C").Value = "C1";
            
            //Set Excel property values
            workbook.Properties.Title= "Sample";
            workbook.Properties.Author = "iDiTect";
            workbook.Properties.Subject = "iDiTect.Excel Sample";
            workbook.Properties.Keywords = "iDiTect.Excel";
            workbook.Properties.Category = "iDiTect.Excel";
            workbook.Properties.Company = "iDiTect.com";

            //Set custom property values
            workbook.CustomProperties.Add("CustomProperty1", "Custom Value1");

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

        public static void LoadFromTemplate()
        {
            string template = "template.xlsx";
            var workbook = new Workbook(template);

            //Read all data in worksheet by id
            var templateSheet = workbook.Worksheet(1);

            //Load data from cell by row and column coordinate
            var A1 = templateSheet.Cell(1, 1).Value;
            Console.WriteLine(A1.ToString());

            //Load data from cell by range name
            var C2 = templateSheet.Cell("C2").Value;
            Console.WriteLine(C2.ToString());

            //After load the existed excel file, you can modify cell value, style, formula, add chart, table...

            //Update cell value or add value to new cell
            templateSheet.Cell("A1").Value = "update";
            templateSheet.Cell("A10").Value = "new";
            //... and any other editing

            //Or create a new worksheet
            var worksheet = workbook.Worksheets.Add("NewTab");
            //do anything you want

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



    }
}
