首页 > 解决方案 > 如何读取现有的 Excel 电子表格单元格(或多个单元格)

问题描述

(如果我的问题或描述太模糊,请纠正我)

我想从 WinForms 的 Excel 电子表格(不是所有内容,只是几个单元格)中的单元格中读取数据,使用该数据并将其显示为标签的文本。一个很好的例子是,某人将其产品的库存存储在电子表格中,但只想知道其库存中存在的 x 产品的数量。

标签: excelvb.netwinforms

解决方案


尝试这个

Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Add("Your file path here")
xlWorkSheet = xlWorkBook.Sheets("sheet1") ' Your sheet name is here
Label1.Text = xlWorkSheet.Range("B2").Value 'cell no from where you want to fetch data 

推荐阅读