Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Following is vb statement:
ApExcel.Worksheets(1).Cells(1, 19) = "=COUNT(c[-18])";

how to convert above to c# statement? what "=COUNT(c[-18])" this mean

What I have tried:

I am new to vb please help me
My excel sheet contain total 18 columns.and i have to add records accordingly.
Posted
Updated 6-Jun-16 22:24pm
Comments
Matt T Heffron 7-Jun-16 0:23am    
It's setting that cell (1,19) of worksheet 1 to be the string "=COUNT(c[-18])"
That's an Excel function call.
Not VB
Anup6 7-Jun-16 0:49am    
Ok.What is the value of this "=COUNT(c[-18])"?
Dave Kreskowiak 7-Jun-16 0:55am    
Impossible to determine as it's entirely dependent on the contents of the Excel sheet you're playing around with.
Anup6 7-Jun-16 1:16am    
please tell me what is mean by 'c' and'[-18]' in that formula

converted c# statement is:
note: Module1.ScaleType is 1

ReflectionHelper.LetMember(ReflectionHelper.Invoke(ApExcel, "Worksheets", new object[] { Module1.ScaleType }), "Cells", "=COUNT(c[-18])", 1, 19);
i Got error "Exception from HRESULT: 0x800A03EC"
LesF 7-Jun-16 3:33am    
You should look at the Office API for .Net, as what you really want is to get an instance of a Excel worksheet object and use it's methods and properties.

Your code will look almost the same as the VB code, as you will be using a very similar API. Try the Microsoft guides first, they often have good examples, such as:

[How to automate Microsoft Excel from Microsoft Visual C#.NET]

1 solution

Quote:
C#
ApExcel.Worksheets(1).Cells(1, 19) = "=COUNT(c[-18])";
First of all this code have a problem. An Excel cell is an object, you can't store a string in it and expect anything go right.
To store a formula in the cell, you need to say it.
C#
ApExcel.Worksheets(1).Cells(1, 19).FormulaR1C1 = "=COUNT(c[-18])";

Quote:
what "=COUNT(c[-18])" this mean
This is an Excel formula using the R1C1 relative notation.
Excel VBA FormulaR1C1 Property - Easy Excel Macros[^]
Excel – R1C1 Reference Style vs. A1 | Excelmate[^]
 
Share this answer
 
Comments
Anup6 7-Jun-16 7:43am    
Thanks to all.@ppolymorphe ,provided links are useful thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900