0
votes

I'm using closedxml to generate a excel file. I'm mapping the cells directly in excel by creating a named range and inside of it reaching the items in the range by {{item.property}}, the range collection is added like a variable in the code.

The item I'm using has a Year property and a month property, the mapping in that excel cell is: {{item.Yr}}/{{item.Mon}}.

I would like Excel to format the value in the cell to mmm-yyyy (Jan-2020). Which it does if I directly write a date in the cell in Excel and presses Enter, but that's not what I want, I want it to format my generated value.

I've tried using the functions like =TEXT(date,format) or =DATEVALUE("1/1/2015"). But the problem is that I can't write directly "1/1/2015", I need to write something like DATEVALUE(1/{{item.Mon}}/{{item.Yr}} but Excel syntax doesn't allow this. Ofcourse I've also tried just the "format cell" to date on the cell, but doesn't work (only if I directly type a date and presses Enter)

I'm sorry for my crappy explanation. I hope someone understands what I mean and what I want to accomplish.

1
try =Date({{item.Yr}},{{item.Mon}},1) then format as desired. - Scott Craner
@ScottCraner I only get the popup saying "there's a problem with this formula" as soon as I'm using {{item.property}} in a function - Amanda Eriksson

1 Answers

0
votes

SOLVED

After 2 days banging my head against the wall, I found that If a variable is used in a formula, it needs to be escaped with "&" at the beginning:

&=Date({{item.Yr}},{{item.Mon}},1).