创建Excel加载项 - 获取单元格值 [英] Create Excel Add-in - get cell value
本文介绍了创建Excel加载项 - 获取单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用visual studio 2010创建了一个excel加载项。我可以使用此代码获取单元格地址。
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.
请帮助。
推荐答案
活动单元格应该这样做
var cellValue = Globals.MyAddIn.Application.ActiveCell.Value.ToString()
或特定单元格
var cellValue = Globals.MyAddIn.Application.Cells("A1").Value.ToString()
设置值基本上是相反的
Globals.MyAddIn.Application.Cells("A1").Value = "ABC123"
EDIT
尝试这个。我知道这个工作,因为我有一些像它在我自己的addin中工作。
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];
这篇关于创建Excel加载项 - 获取单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文