加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

[VB.NET]如何打开EXCEL同时得到它的每个标签

发布时间:2020-12-16 23:43:21 所属栏目:大数据 来源:网络整理
导读:如何打开EXCEL同时得到它的每个标签 我目前导入得这样写哦 Dim ConnString As String = ( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= D:aa.xls;Extended properties=Excel 5.0 ") Dim SQLString As String = " select * from [sheet1$] " 这样得出来的
如何打开EXCEL同时得到它的每个标签 我目前导入得这样写哦 Dim ConnString As String = ( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= D:aa.xls;Extended properties=Excel 5.0 ") Dim SQLString As String = " select * from [sheet1$] " 这样得出来的只有一个标签,我以前看人家用Delphi做过,打开可以显示所有标签的 不知道VB.net是不是有这么一人控件我不清楚的!~ __________________________________________________________________________ 郁闷死掉,所以学VB.net没人会吗,不会也吱下~~ __________________________________________________________________________ 参考一下我写的东东 http://www.cnblogs.com/linfuguo/archive/2006/08/19/480976.html __________________________________________________________________________ Me.xlApp = CreateObject( "Excel.Application ") Me.xlBook = Me.xlApp.Workbooks.Open(strExcelFilePath) iPage = Me.xlBook.Worksheets.Count Me.ComboBox1.Text = String.Empty Me.ComboBox1.Items.Clear() For i As Integer = CType(strExcelBeginSheet,Integer) To iPage xlSheet = Me.xlBook.Worksheets.Item(i) Me.ComboBox1.Items.Add(xlSheet.Name) Next __________________________________________________________________________ Public Class ExcelDatabase Private Const CONNECTIONSTRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= {0};Extended properties=Excel 5.0 " Private gFile As String Public Sub New(ByVal file As String) gFile = file End Sub Private Function GetConnection() As OleDbConnection Return New OleDbConnection(String.Format(CONNECTIONSTRING,gFile)) End Function Public Function GetCommand(ByVal cmdtext As String) As OleDbCommand Return New OleDbCommand(cmdtext,GetConnection) End Function Public Function GetDataAdapter(ByVal cmdText As String) As OleDbDataAdapter Return GetDataAdapter(GetCommand(cmdText)) End Function Public Function GetDataAdapter(ByVal cmd As OleDbCommand) As OleDbDataAdapter Return New OleDbDataAdapter(cmd) End Function Public Sub Fill(ByVal cmdtext As String,ByVal table As DataTable) Using ad As OleDbDataAdapter = GetDataAdapter(cmdtext) ad.Fill(table) End Using End Sub Public Sub Fill(ByVal cmdtext As String,ByVal dataset As DataSet) Using ad As OleDbDataAdapter = GetDataAdapter(cmdtext) ad.Fill(dataset) End Using End Sub Public Sub Fill(ByVal cmdtext As String,ByVal dataset As DataSet,ByVal srcTable As String) Using ad As OleDbDataAdapter = GetDataAdapter(cmdtext) ad.Fill(dataset,srcTable) End Using End Sub Public Function GetSchemaTable() As DataTable Dim table As New DataTable Using cn As OleDbConnection = GetConnection() cn.Open() table.Load(cn.GetSchema.CreateDataReader) End Using Return table End Function Public Function GetSchemaTable(ByVal collectionName As String) As DataTable Dim table As New DataTable Using cn As OleDbConnection = GetConnection() cn.Open() table.Load(cn.GetSchema(collectionName).CreateDataReader) End Using Return table End Function Public Shared Function Instance(ByVal file As String) As ExcelDatabase Return New ExcelDatabase(file) End Function End Class __________________________________________________________________________ 所有的工作表: Private Sub Button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button2.Click Dim file As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "/变动情况.xls " Me.DataGridView1.DataSource = ExcelDatabase.Instance(file).GetSchemaTable( "Tables ") End Sub __________________________________________________________________________ jlbaowei(豹尾) me.xlapp是哪来的,要声明哪个空间哦... 水如烟的,程序出错 创建文件失败,不知道是啥原因 Public Function GetSchemaTable(ByVal collectionName As String) As DataTable Dim table As New DataTable Using cn As OleDbConnection = GetConnection() cn.Open()----------创建文件失败 table.Load(cn.GetSchema(collectionName).CreateDataReader) End Using Return table End Function Public Shared Function Instance(ByVal file As String) As ExcelDatabase Return New ExcelDatabase(file) End Function End Class ----------------------------------------------------------------------------- 我更希望的效果是点一个按钮,然后打开一个EXcel,这个简单,然后Datagridview中能显示标签吗?如果不行,至少要拉一个combobox,让combobox的item等于打开Excel的标签,Datagridview默认显示在第一个标签,切换Item时,datagridview要能发生变化.只要能得出来,发生变化不是难度吧~ __________________________________________________________________________ GetOleDbSchemaTable用这个可以得到的,你看下微软里的这个使用方法 __________________________________________________________________________ 我的file和你的file不一样.你按你的来改变量值. __________________________________________________________________________

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读