开发者

Excel manipulation from C# - Set ActiveCell?

What is the C# equilivant to this V开发者_StackOverflow中文版B6 to setting of the active cell?

ActiveSheet.Range("L1").Select


Here's a sample piece of code:

        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 to you just the Select method as before to select a range, although I haven't tested this.

        rng.Select();

You can obviously streamline this and chain these statements together, with the right casting. I don't want to hazard a guess here as I've not got a VSTO project open in from of me.

EDIT

You should also be able to get a range from the sheet using get_Range:

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

VSTO tends to return Objects most of the time, necessitating casts, but get_Range is an exception. Someone might be able to correct me as I am not a big user of VSTO (still VBA die-hard when it comes to Excel).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜