'Excel corrupting formula with @
I'm using EPPlus in my C# code to create an Excel workbook. My code includes this statement:
ws.Cells[1, 1].Formula = "=UNICHAR(160)";
But when I execute my code and open the Excel workbook that it generates, cell A1 displays the error #NAME? The Excel error message states, "The formula contains unrecognized text."
The reason for the error is that cell A1 doesn't contain the formula that I entered. It actually contains the formula =@UNICHAR(160). Excel has inserted an extraneous @ as the second character of the formula, thereby corrupting it.
Why is Excel converting my valid formula =UNICHAR(160) into an invalid formula =@UNICHAR(160), and how can I make it stop corrupting what I've written?
Solution 1:[1]
It appears that there's no way to prevent the insertion of @ into the =UNICHAR(160) formula. The answer to the Stack Overflow question noted by Solar Mike indicates that implicit intersection is here to stay.
As a workaround, I was able to use the formula =CHAR(160) instead, and Excel didn't corrupt that. For some reason, Excel appears to treat =CHAR(160) as returning a single value, but =UNICHAR(160) as returning a range of values, so it adds the @ symbol to return only the first value in the range, even though the unicode character 160 isn't really a range.
Although replacing UNICHAR() with CHAR() isn't a workable solution for rendering any unicode character, it appeared to fix my specific problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
