如何打开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.Combo
Box1.Text = String.Empty Me.Combo
Box1.Items.Clear() For i As Integer = CType(strExcelBeginSheet,Integer) To iPage xlSheet = Me.xlBook.Worksheets.Item(i) Me.Combo
Box1.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中能
显示标签吗?如果不行,至少要拉一个combo
Box,让combo
Box的item等于打开Excel的
标签,Datagridview默认
显示在第一个
标签,切换Item时,datagridview要能发生变化.只要能得出来,发生变化不是难度吧~ __________________________________________________________________________ GetOleDbSchemaTable用这个可以得到的,你看下微软里的这个使用
方法 __________________________________________________________________________ 我的file和你的file不一样.你按你的来改变量值. __________________________________________________________________________
原文链接:https://www.f2er.com/vb/263758.html