1

I would like to write a formula in a Excel cell with SpreadSightLight in C#. I have a following formula in excel

=COUNTIFS(Sheet2!E:E, D2, Shet2!A:A, ">0")

In the code it looks

"=COUNTIFS({0}!E:E,{1},{0}!A:A ,\">0\")";  

I save the file from the code, but when i try to open the file Excel (2013) gives error message and the formula is removed

Removed Records: Formula from /xl/worksheets/sheet3.xml part

and the sheet3.xml contains the following line

COUNTIFS(Sheet2!E:E, D2, Sheet2!A:A ,">0")

I tried the verbatim string and the char(34) solutions also but causes the same error.

How can I solve this problem? Thanks in advance.

4
  • is it complete line of code? show one complete... Commented Aug 2, 2013 at 14:34
  • I have never heard of SpreadSightLight and so I googled it... I only got 5 results all pointing to only this question... Commented Aug 2, 2013 at 15:14
  • sorry @chancea I misspelled. It's called SpreadSheetLight. Commented Aug 2, 2013 at 18:46
  • Hi, @KazJaw. The complete line of code is: string formula = "=COUNTIFS({0}!E:E,{1},{0}!A:A ,\">0\")"; and the code to write: Write(string.Format(formula, sheetName, SLConvert.ToCellReference(StartRow, StartColumn + 2)), style2); (where 'Write' is a own method to use 'SetCellValue' and 'SetCellStyle' together) Commented Aug 5, 2013 at 6:53

2 Answers 2

1

I have not succeed to find the reason why there can be no double quotes written into an excel formula. However there is a solution to avoid double quotes:

string formula = "=COUNTIFS({0}!E:E, {1}, {0}!A:A , CONCATENATE(CHAR(62), CHAR(48)))";

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

Comments

0

In case anybody subsequently comes across this thread, I believe the problem is the greater than sign. It's getting confused with the end tag in XML. So it needs to be replaced by &gt (as hinted at by what you said your sheet3.xml contains). I think the double quotes are fine as you have them - escaped with a preceding backslash.

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.