views:

774

answers:

1

hi, can anyone tell me why this does not work

 Excel.Worksheet ws_res = (Excel.Worksheet)
                  wb.Worksheets.Add(mis, mis, mis, mis);
  Excel.Range range_res = (Excel.Range)ws_res.get_Range("A1","HM232");
 range_res.FormulaArray = 
           "=ROUND((IF((IF(Sheet4!A1:HM232=1,0,"+
           "IF(Sheet4!A1:HM232=0,1,Sheet4!A1:HM232)))=1,0,"+
           "IF((IF(Sheet4!A1:HM232=1,0,"+
           "IF(Sheet4!A1:HM232=0,1,Sheet4!A1:HM232)))=0,1,("+
           "IF(Sheet4!A1:HM232=1,0,"+
           "IF(Sheet4!A1:HM232=0,1,Sheet4!A1:HM232)))))),0)";

but this does

   Excel.Worksheet ws_res = (Excel.Worksheet)
                  wb.Worksheets.Add(mis, mis, mis, mis);
  Excel.Range range_res = (Excel.Range)ws_res.get_Range("A1","HM232");
  range_res.FormulaArray = 
  "=ROUND((IF(Sheet4!A1:HM232=1,0,IF(Sheet4!A1:HM232=0,1,Sheet4!A1:HM232))),0)";

=======================================================

but if i copy and paste the above two formulas to the formula bar of excel-2007 and press Ctrl+Shift+Enter, both work perfectly!

=======================================================

i have also changed in the above two formulas A1:HM232 to R1C1:R232C221, again from c# the shorter one works fine, but the longer one still generates the exception!

A: 

It works for me. I have to assume either that you don't have a Sheet4 (unlikely, since the shorter formula works) or that you made a typo when removing the Quotes, "+"s, and line breaks. Here is what I have in my formula bar now:

=ROUND((IF((IF(Sheet4!A1:HM232=1,0,IF(Sheet4!A1:HM232=0,1,Sheet4!A1:HM232)))=1,0,IF((IF(Sheet4!A1:HM232=1,0,IF(Sheet4!A1:HM232=0,1,Sheet4!A1:HM232)))=0,1,(IF(Sheet4!A1:HM232=1,0,IF(Sheet4!A1:HM232=0,1,Sheet4!A1:HM232)))))),0)
RBarryYoung
if i copy and paste both above formula directly to Excel 2007 formula bar then they both work perfect!but the problem arises with the longer formula when i try to run my c# program... there is no syntax error since both formulas are being generated automatically...