I have a problem with writing functions from C# into Excel file.
private void AddDemandFunctions()
{
Func<string, string, string> function = (range, shift) =>
{
var builder = new StringBuilder();
builder.Append("=LICZ.JEŻELI(");
builder.Append(range);
builder.Append("; \"");
builder.Append(shift);
builder.Append("\")");
return builder.ToString();
};
int startRow = 5;
int endRow = 20;
string [] columns = { "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ", "AK", "AL", "AM" };
foreach (var column in columns)
{
string range = column + startRow + ":" + column + endRow;
worksheet.Range[column + 21].Formula = function(range, "D"); // HERE I GET AN EXCEPTION RIGHT IN MY FACE :(
worksheet.Range[column + 22].Formula = function(range, "E");
worksheet.Range[column + 23].Formula = function(range, "L");
worksheet.Range[column + 24].Formula = function(range, "N");
}
}
The exception is:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Wyjątek od HRESULT: 0x800A03EC.
My Excel(2010) is Polish language version. When I tried to delete "=" it works, but it writes only text. Then, if I add "=" inside excel file everything is ok. There is no mistake inside the function string.
I also tried with non-polish function: COUNTIF
and I have the same exception...
Any ideas?
Greetings from PL :)