名前付きセルの位置および列数・行数を取得する方法を説明します。

セルの行・列の位置を取得する

Dim FilePath As String = "C:\work\HelloWorld.xlsx"

Using book As XLWorkbook = New XLWorkbook(FilePath)
    Dim wksheet As IXLWorksheet = book.Worksheet(1)

    Dim Range1 As IXLRange = wksheet.Range("ALL")

    '列の位置を取得
    Dim x As Integer = Range1.Cell(1, 1).Address.ColumnNumber
    '行の位置を取得
    Dim y As Integer = Range1.Cell(1, 1).Address.RowNumber
End Using

 

セルの行・列の数を取得する

Dim FilePath As String = "C:\work\HelloWorld.xlsx"

Using book As XLWorkbook = New XLWorkbook(FilePath)
    Dim wksheet As IXLWorksheet = book.Worksheet(1)

    Dim Range1 As IXLRange = wksheet.Range("ALL")

    '列の数を取得
    Dim cols As Integer = Range1.ColumnCount
    '行の数を取得
    Dim rows As Integer = Range1.RowCount

    'または

    '列の数を取得
    Dim cols As Integer = Range1.Columns.Count
    '行の数を取得
    Dim rows As Integer = Range1.Rows.Count
End Using

 

※Cell()は、1から数えるみたいですCell(0,0)ではA1の位置を取得するとエラーとなる