How to focus or select a cell in Excel

后端 未结 3 2072
感动是毒
感动是毒 2021-01-17 10:58

How to focus a cell in Excel VSTO using C# or to select first cell using C# in VSTO?

相关标签:
3条回答
  • 2021-01-17 11:00
     Excel.Application ExcelApp = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
                Excel.Workbook book = ExcelApp.ActiveWorkbook;
                Excel.Worksheet sheet = book.ActiveSheet;
                Excel.Range ExcelRange = sheet.get_Range("A1");
                ExcelRange.Select();
    
    0 讨论(0)
  • 2021-01-17 11:12

    Here is one way:

    Excel.Worksheet activeSheet = ThisAddIn.ExcelApplication.ActiveSheet;
    var range = activeSheet.get_Range("A1", "A1");
    range.Select();
    

    ThisAddIn is the name of my test project.

    0 讨论(0)
  • 2021-01-17 11:19

    To select the A2 cell, for example:

    Excel.Worksheet Worksheet = excel.ActiveWorkbook.ActiveSheet;
    Worksheet.get_Range([1,2], System.Reflection.Missing.Value).Select();
    
    0 讨论(0)
提交回复
热议问题