0

I'm newbie in C#. I tried to insert strings from DataTable into Excel cells formulas, but unsuccesfully. For example, I have

=ROUND(R[-2]C*IF(R[-1]C="";R[-1]C17;R[-1]C)/(IF(R[-1]C="";R[-1]C17;R[-1]C));2)

as value. I also tried to make

=ROUND(R[-2]C*IF(R[-1]C=\"\";R[-1]C17;R[-1]C)/(IF(R[-1]C=\"\";R[-1]C17;R[-1]C));2)

But I got an exception from HRESULT: 0x800A03EC In the last example debugger shows proper string, but I also got that exception.

Also, it works, when I put this code:

Globals.Wirksheet1.Cells.Range["A100"].Value2 = @"=ROUND(R[-2]C*IF(R[-1]C="""",R[-1]C17,R[-1]C)/(IF(R[-1]C="""",R[-1]C17,R[-1]C)),2)";

But I need to get values from DataTable, also I don't know how to add @ to string. Please, explain me how to solve this problem? Thanks

Michael
  • 3
  • 4
  • Have you seen this answer http://stackoverflow.com/questions/7099770/hresult-0x800a03ec-on-worksheet-range – Mauricio Gracia Gutierrez Sep 04 '13 at 19:46
  • Thanks, but it is not my case. The problem with mycode is converting double quotes to Excel formulas. – Michael Sep 04 '13 at 20:00
  • I solved it on Excel side :) I changed values in my Table Data to =ROUND(R[-2]C*IF(R[-1]C=CONCATENATE(CHAR(34),CHAR(34)),R[-1]C17,R[-1]C)/(IF(R[-1]C=CONCATENATE(CHAR(34),CHAR(34)),R[-1]C17,R[-1]C)),2) – Michael Sep 04 '13 at 21:36

1 Answers1

0

For the sake of an answer.

OP has stated:

I changed values in my Table Data to

=ROUND(R[-2]C*IF(R[-1]C=CONCATENATE(CHAR(34),CHAR(34)),R[-1]C17,R[-1]C)/(IF(R[-1‌​]C=CONCATENATE(CHAR(34),CHAR(34)),R[-1]C17,R[-1]C)),2)

pnuts
  • 58,317
  • 11
  • 87
  • 139