I have a problem that I can't solve. I need to pass a value from one Selenium test to another. And the writing part works just fine. I saves the value to an excel file. The problem appears when I try to read it. I have a class which should be able to read the cell, but it won't.
Excel.cs
using System.IO;
using OfficeOpenXml;
using excel = Microsoft.Office.Interop.Excel;
namespace Core
{
public sealed class Excel
{
#region Private Properties
private static string InputPath { get; } = ConfigSettingProvider.InputSourcePath;
private static string OutputPath { get; } = ConfigSettingProvider.OutputSourcePath;
#endregion Private Properties
public static string ReadCell (int sheet, int x, int y) // (sheet, row, column)
{
FileInfo existingFile = new FileInfo("..\\..\\..\\Property\\Input\\data1.xlsx");
using (ExcelPackage package = new ExcelPackage(existingFile))
{
return package.Workbook.Worksheets[sheet].Cells[x, y].Value.ToString();
}
}
}
}
And then in Test Fixture class I am trying to call ReadCell method:
var cellPolicyNo = Excel.ReadCell(1, 1, 1);
But it simply won't even enter to read it. Immediately the exception is thrown: "The type initializer for 'Core.Excel' threw an exception". at Core.Excel.ReadCell(Int32 sheet, Int32 x, Int32 y)
What am I doing wrong? What should I change?
Thank you