2

I would like to write a formula in a Excel cell. I managed to write simple formula but I have an issue with the following formula :

=IF(OR(ISBLANK(I20631);ISBLANK(F20631));"";I20631=F20631)

In my C# programm it tried this :

ExcelWorksheet.Cells[row, column] = "=IF(OR(ISBLANK(I" + row +");ISBLANK(F" + row +"));\"\";I"+ row +"=F" + row +")";

I have an exeption because of the \"\" (I think so)

When I write in the excel cell, Excel cannot interpeter \" as the double quote symbole " And I can't write a string with visual studio whithout writting the \"

Is it possible to have another way to write a string with double quote character whitout using \" ? (I alos tried " but it is still interpreted as \" )

Thank you in advance,

Thomas

Martin Mulder
  • 12,642
  • 3
  • 25
  • 54
user2310493
  • 103
  • 2
  • 7
  • What exception are you getting? I think it's more likely that the `+ row` gives you an exception rather than the `\"`. Try replacing `+ row` with `+ row.ToString()`. – Roy Dictus Apr 29 '13 at 12:07
  • I changed row to row.tostring() and (char)34 but I still have the following exception : System.Runtime.InteropServices.COMException was unhandled Message=Exception from HRESULT: 0x800A03EC Source="" ErrorCode=-2146827284 StackTrace: at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData) – – user2310493 Apr 29 '13 at 12:27

2 Answers2

1

Yes, put an @ before the string. This will "disabled" the escape character \. The only thing that is enabled is the use of two double quotes which will translate into one double quote.

Example:

 "I said: \"Hello!\""

is equal to:

 @"I said: ""Hello!"""

is equal to:

 "I said: " + (char)34 + "Hello!" + (char)34

Which will producte when printed:

 I said: "Hello!"

Be aware: How ever you format your string, the debugger will ALWAYS show your string as the first string, with \. This does not mean that these backslashes are part of the string, it is just a way of showing them.

Martin Mulder
  • 12,642
  • 3
  • 25
  • 54
0

As Roy mentioned, the compiler should take the String without backslash if you escape like you did, but you can also give the Verbatim String Literal Martin mentioned a try..

See MSDN for examples of them..

Sven Mawby
  • 645
  • 6
  • 16