excel - 如何读取现有的 Excel 电子表格单元格(或多个单元格)
问题描述
(如果我的问题或描述太模糊,请纠正我)
我想从 WinForms 的 Excel 电子表格(不是所有内容,只是几个单元格)中的单元格中读取数据,使用该数据并将其显示为标签的文本。一个很好的例子是,某人将其产品的库存存储在电子表格中,但只想知道其库存中存在的 x 产品的数量。
解决方案
尝试这个
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
推荐阅读
- python - Dm 每个有角色的人 discord.py
- node.js - 使用 lowdb 会导致 ERR_REQUIRE_ESM
- javascript - 动态更新变量名
- python - 如何从另一个类方法继承变量
- r - 如何绑定列表中的 data.frames 行并添加一个包含列表元素名称的新列?
- json - 数据类型映射:提取几个原子值
- flutter - 在flutter getx中对空值使用空检查运算符
- javascript - html javascript在主页中存储多个页面
- rust - 在 gtk-rs 中,如何获取 gtk::Window (大部分)在的当前屏幕?
- c - 如何检查一个大的二进制文件是否包含另一个文件的内容?