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

2
  • 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(). Commented Apr 29, 2013 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) – Commented Apr 29, 2013 at 12:27

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.