从 Excel 文件中选择所有工作表
基本上,我正在上传一个动态 Excel 文件,我想选择包含数据的所有工作表并将其放入数据集中。但我不知道如何,我所能得到的只是一个静态工作表名称,并且每个选择只有一张工作表,我如何选择一个 Excel 文件中的所有 shhet 并将其放入数据集中?谢谢。
这就是我到目前为止所得到的
Dim exConS As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
excelfile & ";Extended Properties=Excel 8.0;"
Dim exCon As New OleDbConnection(exConS)
Dim dsExcel As New DataSet()
Dim sExcel As String = "SELECT * FROM [SSI-data3$]"
Dim daExcel As New OleDbDataAdapter(sExcel, exCon)
daExcel.Fill(dsExcel)
basically, i am uplaoding a dynamic excel file and i want to select all the sheets containing a data and have it in a dataset. But i dont know how, all I can get is from a static sheet name and only one sheet per select, how can i select all shhet within one excel file and have it in a dataset? thanks.
this is what i got so far
Dim exConS As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
excelfile & ";Extended Properties=Excel 8.0;"
Dim exCon As New OleDbConnection(exConS)
Dim dsExcel As New DataSet()
Dim sExcel As String = "SELECT * FROM [SSI-data3$]"
Dim daExcel As New OleDbDataAdapter(sExcel, exCon)
daExcel.Fill(dsExcel)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您可以使用 GetSchema 以及来自 Jet 架构集 用于检索表的名称 - 在 Excel 中,这包括命名的表范围和表格。
您必须创建一个 UNION 查询来获取一组数据中的每个工作表,这仅适用于列匹配的情况。
I think you can use GetSchema with suitable schema name from the Jet schema set to retrieve the names of tables - in Excel, this includes both named ranges and sheets.
You would have to create a UNION query to get every sheet in the one set of data, which would only be suitable if the columns matched.
我认为您应该使用
Microsoft.Office.Interop.Excel
获取工作表名称,然后使用foreach
获取它们I think you should use
Microsoft.Office.Interop.Excel
to get worksheet names and then with aforeach
you can get them