using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MsXl = Microsoft.Office.Interop.Excel;

namespace XLreader
{
    public class ReadXlClass
    {
        
        public static string[] ReadXl(string filename, int[] sheet, int[] rows, int[] col, int XlLength)
        {
            
            MsXl.Application apxl = new MsXl.Application();
            MsXl.Workbook xlwb = apxl.Workbooks.Open(filename, ReadOnly: true);
            MsXl.Worksheet xlws = (MsXl.Worksheet)xlwb.ActiveSheet;

            
            string[] Xlout = new string[XlLength];

            for (int i = 0; i < XlLength; i++)
            {
                if (xlws.Cells[rows[i], col[i]].Value2 == null)
                {
                    Xlout[i] = null;
                }
                else
                {
                    Xlout[i] = xlws.Cells[rows[i], col[i]].Value.ToString();
                }
            }

            xlwb.Close();
            apxl.Quit();
            
            return Xlout;
        }
       
    }
}
