如何在vb.net中获得Excel单元格名称?

我需要列的第一个空单元格的名称,例如“E15”或“A3”我尝试使用worksheet.Cells.Name和worksheet.Rows.Name,但我不认为这是正确的语法。 .. 请帮忙!

这是我的代码

Dim xlApp As Excel.Application Dim xlWorkBook As Excel.Workbook Dim xlWorkSheet As Excel.Worksheet Dim misValue As Object = System.Reflection.Missing.Value xlApp = New Excel.Application xlWorkBook = xlApp.Workbooks.Add(eXe) xlWorkSheet = xlWorkBook.Sheets("sheet1") Dim eColumn As Excel.Range = xlWorkSheet.Range("E2:E15") Dim rCell As Excel.Range For Each rCell In eColumn If rCell Is Nothing Then Dim LastCell As String = xlWorkSheet.Rows.Name MsgBox(LastCell) End If MsgBox(rCell.Value) Next rCell 

(更新)

我用下面的代码,得到$ E $ 15,有没有办法让地址出“$”符号?

 For Each rCell In eColumn If rCell.Value = "" Then Dim LastCell As String = rCell.Cells.Address MsgBox(LastCell) End If MsgBox(rCell.Value) Next rCell 

要获取颜色的使用名称:

 Dim columnLetter As String = ColumnIndexToColumnLetter(85) ' returns CG Private Function ColumnIndexToColumnLetter(colIndex As Integer) As String Dim div As Integer = colIndex Dim colLetter As String = String.Empty Dim modnum As Integer = 0 While div > 0 modnum = (div - 1) Mod 26 colLetter = Chr(65 + modnum) & colLetter div = CInt((div - modnum) \ 26) End While Return colLetter End Function 

事情你已经知道如何得到你正在寻找的行号。 那就用吧

 dim CellName as String = columnLetter & rownum ' the row number you need 

这应该省略你不想要的任何$符号

这个例子是从这里拿走的

问候,Iakov