Reputation: 129
I want to write this code in 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);
But I cant write "Harm"
in "". How to solve this?
Upvotes: 2
Views: 1457
Reputation: 12815
You need to escape the quotes by preceding them with a \
so the line would become
excelCellrange.Formula = "=IF(A1=\"Harm\",100)";
Upvotes: 0
Reputation: 118947
You need to escape your quotation marks like this:
excelCellrange.Formula = "=IF(A1=\"Harm\",100)";
You can find a good list of escape sequences here: http://blogs.msdn.com/b/csharpfaq/archive/2004/03/12/what-character-escape-sequences-are-available.aspx
Upvotes: 6