开发者

access specific cell from excel add-in vsto

How can I access as specific cell B1 from my excel add-in vsto in microsoft visual studio 2010.

Globals.Sheet1.Range(“B3”).Value this does not work as it seems its the syntax for excel document instead of excel add-in.


edit this seems to work

    Microsoft.Office.Interop.Excel.Worksheet activeSheet = Globals开发者_运维知识库.ThisAddIn.Application.ActiveSheet as Microsoft.Office.Interop.Excel.Worksheet;
    var currentCells = activeSheet.get_Range("A1", "E1");
    currentCells.Select();

but then how do I select specific values in currentCells?


Try something along these lines:

var excel = Globals.ThisAddIn.Application;
var activeSheet = (Worksheet)excel.ActiveSheet;
var cell = activeSheet.Range["B1", Type.Missing];
var content = cell.Value2;


You could do Range.Find(...), and then FindNext, adding found cells to list

Alternatively, you could iterate over all Range.Item[i,j] for i = 1 to Range.Rows.Count (==1 in your case) and j=1 to Range.Columns.Count like this and check the values of individual cells as you go.

Use Application.Union to combine multiple Ranges from the acquired list and do Select() on the combined range

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜