0

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 :)

4
Contributors
4
Replies
8
Views
9 Years
Discussion Span
Last Post by SuperSid
0

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.

0

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";

0

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!

0

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;

Edited by SuperSid: solved

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.