c# - 从所有 Excel 工作表中创建一个数组
问题描述
我有一个通过 OpenFileDialog 函数连接到 Excel 数据库的 C# 代码。Excel 文件有太多工作表,我想将它们的所有名称放在一个数组中并将它们添加到组合框。例如,这是第一个 Excel 文档。
有什么建议么?
解决方案
您可以尝试以下方法:
Accord.IO.ExcelReader reader = new Accord.IO.ExcelReader("youFile.xlsx");
string[] worksheets = reader.GetWorksheetList();
确保包括
using Accord.IO;
您可以通过搜索 Accord 和 Accord.IO 从 NuGet 获取 Accord。
然后只需填写组合框的项目
foreach (string worksheet in worksheets)
{
myComboBox.Items.Add(worksheet);
}
推荐阅读
- python - 与多处理一起使用时 Pandasql 挂起
- excel - 通过 VBA 在 Excel 中删除换行符会导致溢出错误
- javascript - 浏览器检测所需的实际图像大小
- python - 如何遍历硒/数据中电子表格中存在的数据
- angular - 导入的类静态字段未定义
- excel - 表被重命名
- java - Java 8 流:java.lang.IllegalStateException:结束大小 84758 小于固定大小 84764
- python - 从 Django 启动的脚本中导入自定义模块
- java - 使用 eclipse microprofile-config 自定义配置文件
- groovy - 使用 executescript 将文件内容加载到 nifi 属性中