This project has moved. For the latest updates, please go here.

Problem with the formula

Nov 30, 2015 at 9:35 AM
Hello. I have a problem with the recording of the formula in the cell. Formula - "=IF(A6>$A$4;0;1-(E6+F6)/C6)".

Sample Code:

var workbook = new XLWorkbook();
var worksheets = workbook.Worksheets.Add("Sheet 1");

worksheets.Cell(4, 1).Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
worksheets.Cell(6, 1).Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);

worksheets.Cell(6, 3).Value = "3";
worksheets.Cell(6, 5).Value = "5";
worksheets.Cell(6, 6).Value = "6";

worksheets.Cell(2, 2).FormulaA1 = "=IF(A6>$A$4;0;1-(E6+F6)/C6)";

workbook.SaveAs("123.xlsx");



When opening a file I get an error - "Excel found unreadable content in '123.xlsx'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes."

Offline formula in cell (2, 2). Tell me what am I doing wrong?
Feb 4, 2016 at 2:06 AM
Replace the Semicolons ";" with commas "," to read like this:
worksheets.Cell(2, 2).FormulaA1 = "=IF(A6>$A$4,0,1-(E6+F6)/C6)"; 
I will typically test out the formula manually in Excel to see if it works first, and then use it with the same syntax with ClosedXML.