Working with Excel with C # - Install ActiveCell?

I am currently trying to move some VB6 macros to a C # application, and it is difficult for me to set the active cell using C #.

In VB6 its simple:

ActiveSheet.Range("L1").Select

Does anyone know what the equivalent of C # is?

Greetings in advance.

+3
source share
1 answer

Here's a sample code snippet:

        Excel.Worksheet sht = (Excel.Worksheet)ActiveSheet;
        sht.Cells[3, 3] = "HELLO";

You can also capture ranges:

        Excel.Range rng = (Excel.Range)sht.Cells[3, 3];

I believe that you are just the Select method, as before, to select a range, although I have not tested this.

        rng.Select();

You can obviously streamline this and combine these statements with proper casting. I do not want to risk guessing here, because I do not have a VSTO project open from me.

EDIT

, get_Range:

        rng = sht.get_Range("A1", Type.Missing);

VSTO , , get_Range . - , VSTO ( VBA , Excel).

+5

Source: https://habr.com/ru/post/1743535/


All Articles