I have an Excel file with a table tblPhoneCode
and with two columns Country
and Code
, and I have a cell B1 with List Data Validation pointing to the Country
column
and a cell B2 basically it displays the Code
for the selected Country
.
Cell B2 uses the following formula
OFFSET(INDIRECT("tblPhoneCode[#Headers]"),MATCH(B1,INDIRECT("tblPhoneCode[Country]"),0),1,1,1)
Everything in Excel works as it should, but the issue is when I am reading the value of B2 using EPPlus in C# I am getting #VALUE!
instead of the actual Phone Code
. I've tried .Calculate()
from workbook, worksheet, to cell and tried to access the value is still the same. I've attached the logger and it turns up empty and there is no error logged in it.
C# Code
static void Main(string[] args)
{
var excelFile = new FileInfo(@"C:\Users\Ash\Desktop\Epplus.xlsx");
using (var package = new ExcelPackage(excelFile))
{
// Output from the logger will be written to the following file
var logfile = new FileInfo(@"C:\Users\Ash\Desktop\EpplusLogFile.txt");
// Attach the logger before the calculation is performed.
package.Workbook.FormulaParserManager.AttachLogger(logfile);
// Calculate - can also be executed on sheet- or range level.
package.Workbook.Calculate();
Debug.Print(String.Format("Country: \t{0}", package.Workbook.Worksheets[1].Cells["B1"].Value));
Debug.Print(String.Format("Phone Code:\t{0}", package.Workbook.Worksheets[1].Cells["B2"].Value));
// The following method removes any logger attached to the workbook.
package.Workbook.FormulaParserManager.DetachLogger();
}
}
Output:
Country: US
Phone Code: #VALUE!
Any help or insight is much appreciated, I am using MS Excel 2010, .NET 4.0, EPPlus 4.1.0, and Windows 10 64bit