首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

把EXCLE文件内容导入datagrid中解决办法

2012-02-20 
把EXCLE文件内容导入datagrid中在windows form中加个button 单击这个button弹出openfiledialog选好以后 在

把EXCLE文件内容导入datagrid中
在windows form中加个button 单击这个button弹出openfiledialog
选好以后 在DataGird中输出EXCLE中的内容
完全代码 哪位能写个啊 
另 能弄出来给分 但是我不知道怎么给分 所以写完代码 顺便写下给分方法
谢谢各位了

[解决办法]

VB.NET code
Public Class Form1    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        Dim tb As DataTable = Nothing        Using dlg As New OpenFileDialog            With dlg                .Filter = "*.xls|*.xls"                .Multiselect = False                If .ShowDialog = Windows.Forms.DialogResult.OK Then                    Dim db As New LzmTW.Data.ExcelDatabase(.FileName)                    Dim tables As DataTable = db.GetConnectionSchema("Tables")                    '只取第一个                    Dim firstSheet As String = tables.Rows(0)("TABLE_NAME").ToString                    tb = db.GetDataTable("[" & firstSheet & "]")                End If            End With        End Using        If Not tb Is Nothing Then            Me.DataGridView1.DataSource = tb        End If    End SubEnd Class 

热点排行