This project has moved and is read-only. For the latest updates, please go here.

EPPlus 4.0 Beta error for string formula ="Hello"

Sep 18, 2014 at 5:29 AM
The output of below code is #VALUE!. Am i missing something?

string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
var directory = Path.GetDirectoryName(path);
string sourceFile = directory + "\Book1.xlsx";
string targetFile = directory + "\Test1 " + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx";
FileInfo sourceFileInfo = new FileInfo(sourceFile);
FileInfo targetFileInfo = new FileInfo(targetFile);
OfficeOpenXml.ExcelPackage package = new ExcelPackage(targetFileInfo, sourceFileInfo);
ExcelWorkbook book = package.Workbook;
ExcelWorksheet sheet = book.Worksheets["Sheet1"];
//sheet.Cells["B4"].Formula = "IFERROR(1000/2,0)";
sheet.Cells["B4"].Formula = "\"Hello\"";
object value = sheet.Cells["B4"].Value;
sheet.Cells["B5"].Value = value + " World";
Sep 18, 2014 at 12:02 PM
Edited Sep 18, 2014 at 12:02 PM
Hey rm1, I haven't tried all of this in code but if you're just assigning a string to cell B4, then all you should need to do is sheet.Cells["B4"].Value = "Hello"; There should be no need for sheet.Cells["B4"].Calculate(); either because you're not calculating any Excel formula.

For your variable value, you would need
string value = sheet.Cells["B4"].Value.ToString();

then sheet.Cells["B5"].Value = value + " World"; should work.

Also, no need for your final book.Calculate(); because you don't have any Excel formulas above so nothing to calculuate. .Calculate only need to work out an actual Excel formula.