Create Excel Add-in - get cell value

10,378

to get a cell value for the active cell the following should do it

var cellValue = Globals.MyAddIn.Application.ActiveCell.Value.ToString()

or for a specific cell

var cellValue = Globals.MyAddIn.Application.Cells("A1").Value.ToString()

To Set the value it is basically the reverse

Globals.MyAddIn.Application.Cells("A1").Value = "ABC123"

EDIT
Try this. I know that this works as I have something like it working in my own addin.

int row = 1;
int col = 1;
var sheet1 = (Excel.Worksheet)Application.ActiveWorkbook.Worksheets["Sheet1"];
sheet1.Cells[row, col] = "ABC123";

string cellValue = sheet1.Cells[row,col];
Share:
10,378
yohan.jayarathna
Author by

yohan.jayarathna

Updated on June 04, 2022

Comments

  • yohan.jayarathna
    yohan.jayarathna almost 2 years

    I am creating a excel Add-in using visual studio 2010. I was able to get the cell address using this code.

    label1.Label = Globals.MyAddIn.Application.ActiveCell.Address.ToString();
    

    I want to get the cell value. Also if you can tell me how to set a value for a given cell.

    Please help.