using System;
using System.Linq;
using System.Diagnostics;

using Syncfusion.XlsIO;

using XlsioSlowCalculate_17_1.Files;


namespace XlsioSlowCalculate_17_1
{

    public class Program
    {

        private static string[ ] columns = { "H", "I", "J", "S", "T", "U", "AD", "AE", "AF" };

        public static void Main( string[ ] args )
        {
            ExcelEngine excelEngine = new ExcelEngine( );
            var excelApplication = excelEngine.Excel;

            IWorkbook xlsxWorkbook;

            using ( var embedStream = EmbeddedFiles.OpenFile( EmbeddedFiles.ExcelDocumentName ) )
            {
                xlsxWorkbook = excelApplication.Workbooks.Open( embedStream, ExcelOpenType.Automatic );
            }

            var worksheet = xlsxWorkbook.Worksheets.FirstOrDefault( );

            worksheet.EnableSheetCalculations( );

            Stopwatch sw = new Stopwatch( );
            sw.Start( );

            for ( int row = 44650; row < 44653; row++ )
            {
                foreach ( string column in columns )
                {
                    Console.WriteLine( $"{sw.Elapsed} - Updating cell {column}{row}..." );
                    worksheet.CalcEngine.PullUpdatedValue( $"{worksheet.Name}!{column}{row}" );
                }
            }

            Console.WriteLine( $"Time taken = {sw.Elapsed}" );
            Console.ReadKey( );

        }

    }

}
