如何在公式中转义双引号

use*_*553 2 c# excel

我想用C#编写这段代码:

//
excelCellrange = excelSheet.get_Range("B1", "B1");
excelCellrange.Formula = "=IF(A1="Harm",100)";

//Copy formula to other cells:
excelCellrange = excelSheet.get_Range("B2", B10);
excelCellrange.PasteSpecial(Excel.XlPasteType.xlPasteFormulas);
Run Code Online (Sandbox Code Playgroud)

但我不能写"Harm""".怎么解决这个?

Dav*_*idG 6

你需要像这样逃避你的引号:

excelCellrange.Formula = "=IF(A1=\"Harm\",100)";
Run Code Online (Sandbox Code Playgroud)

你可以在这里找到一个很好的转义序列表:http://blogs.msdn.com/b/csharpfaq/archive/2004/03/12/what-c​​haracter-escape-sequences-are-available.aspx