【问题标题】:How to find the adjacent cell value in excel using VB.NET如何使用VB.NET在excel中查找相邻单元格的值
【发布时间】:2014-01-09 12:45:12
【问题描述】:

我被这种情况困住了。我阅读了论坛并尝试了多种方法来解决此问题,但没有任何效果。

这里是场景:

我正在使用 vb.net 自动生成一个 Excel 工作表。此工作表在 A 列中填充了 200 个数据值,在 B 列中填充了 200 个不同的数据值。然后我找到 B 列的最大值及其相关地址(例如 maxvalue = 2.59,地址 $B$89 )。我现在需要找到相邻单元格的值(在 A 列中)并将该值显示在消息框中。

任何帮助将不胜感激。

谢谢

苏迪尔

【问题讨论】:

  • 我们可以看看你试过但没有用的代码吗?

标签: vb.net excel-2010


【解决方案1】:
Dim xlsApp As Excel.Application = Nothing
    Dim xlsWorkBooks As Excel.Workbooks = Nothing
    Dim xlsWB As Excel.Workbook = Nothing

    Try

        xlsApp = New Excel.Application
        xlsApp.Visible = True
        xlsWorkBooks = xlsApp.Workbooks
        xlsWB = xlsWorkbooks.Open("c:\my_excel_file.xls")

        xlsWB.Range("B89").Select   'This will move the cursor to B89 cell
        Dim myValue as String = ""

        myValue = xlsWB.Activecell.Offset(0,-1).Value
                      'Offset(0,-1) means we are interested in the
                      'cell in which lies on the same row (0 for y axis)
                      'and to the left of the current one, by one cell
                      'which means -1 . If we want the cell in column D92 then 
                      'we would use Offset(3,2) 


    Catch ex As Exception

    Finally

        xlsWB.Close()
        xlsWB = Nothing
        xlsApp.Quit()
        xlsApp = Nothing

    End Try

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多