hi
im trying to create a small excel addin in VS2008
byt i cant figure out how to write lika a string or an int to a specific cell?

for example: i want to write something in cell B1?
how do i do that in the C# code? it must be possible?

i tried searching both google an here but havent found anything :/
please help :)

Try this:

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(1, 1).Value = "Test value"

Just alter the objExcel.Cells(1.1) with the cell you want. Test value can be anything you like.

first of all you must install the visual tools for office in your computer
Excel.Worksheet oWorksheet = (Excel.Worksheet)YourApplication.ActiveWorkbook.ActiveSheet;
oWorksheet.Cells[1,1]="populated";

I have a question on this.. I'm using Visual Studio 2010, and the above code:

oWorkSheet.Cells[1,1] = "populated";

only works for Strings.. I can't seem to do it for numbers such as:

oWorkSheet.Cells[1,1] = "0.50";

I tried ToString() as well.. and btw the "populated" and "0.50" from user input in a textbox.. any help would be appreciated!

I found the problem. The excel's cell had a warning that says "this cell is stored as text or preceded by an apostrophe".

So I solved it by putting an apostrophe "'" before the text.. so the code is:

Excel.Range NewCell = (Excel.Range)xlWorkSheet.Cells[3,3];
NewCell.Value2 = "'" + Actual_Weight.Text;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.