2

おはようございます。

Excel相互運用機能の最適化に関する質問の回答を読んだ後、worksheet.Range["A1:C3"](と同じ)を使用してセルを参照するのworksheet.get_range("A1:C3")はあまり便利ではないことがわかりました。整数/長い数値を使用してセルを参照したいのですが、列番号{1、2、3、...}を列文字{"A"、 "B"、 "C "、...}。

注:については知って.Cellsいますが、これは単一セルAFAIKのみを返すため、これはオプションではありません。

何か案が?

よろしく

4

2 に答える 2

3

In Excel macro (VBA) you can use this way:

Dim rngStart As Range
Set rngStart = Range("A1")

Dim rngEnd As Range
Set rngEnd = rngStart.Rows(3).Columns(4)

Dim rngFinal As Range
Set rngFinal = Range(rngStart, rngEnd)

rngFinal.Select

It should be easy rewrite it to C#/VB.NET.

于 2011-05-23T09:34:06.333 に答える
2

You can use the Cells property to create a Range object that can be used as argument to the Range property.

Check out the example here: http://msdn.microsoft.com/en-us/library/bb178282.aspx In the middle of the page you have an example where you use the Cells property to get two range objects that you pass to the Range property instead of passing strings:

With Worksheets(1)
    .Range(.Cells(1, 1), _
        .Cells(10, 10)).Borders.LineStyle = xlThick
End With

In general, the Cells property returns a Range object that you can do whatever you want with: http://msdn.microsoft.com/en-us/library/bb148836.aspx

于 2011-05-23T09:29:09.987 に答える