• 主页
  • VBS
  • .NET技术
  • VBA
  • VB网络编程
  • VB多媒体
  • VB数据库
  • VB控件
  • VB COM/DCOM
  • VB基础类
  • VB API

关于如何使用sql语句查询excel。

zss427607 2014-01-19 09:06:40
如何使用sql查询语句查询,lkl.xls中的表一,将结果放在表二中。

请各位老师指点一下,谢谢了。
...全文
127 点赞 收藏 3
写回复
3 条回复
zss427607 2014年01月20日
谢谢两位的热情帮助。
回复 点赞
JirlangLianHongCh 2014年01月19日
导出EXCEL Private Sub Yaho3() Dim yeah As Object Dim ah As String If Tab1.SelectedTab.Name = "T1" Then yeah = DG3 ah = "種類" ElseIf Tab1.SelectedTab.Name = "T3" Then yeah = DG1 ah = "歸類" ElseIf Tab1.SelectedTab.Name = "T2" Then yeah = DG2 ah = "綜合櫃" End If Dim kk As New SaveFileDialog() kk.Title = "保存EXECL文件" kk.FileName = ah kk.Filter = "EXECL文件(*.xls) |*.xls |所有文件(*.*) |*.*" kk.FilterIndex = 1 If kk.ShowDialog() = DialogResult.OK Then Dim FileName As String = kk.FileName ' + ".xls" If File.Exists(FileName) Then File.Delete(FileName) End If Dim objFileStream As FileStream Dim objStreamWriter As StreamWriter Dim strLine As String = "" objFileStream = New FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write) objStreamWriter = New StreamWriter(objFileStream, System.Text.Encoding.Unicode) For i As Integer = 0 To yeah.Columns.Count - 1 If yeah.Columns(i).Visible = True Then strLine = strLine + yeah.Columns(i).HeaderText.ToString() + Convert.ToChar(9) End If Next objStreamWriter.WriteLine(strLine) strLine = "" For i As Integer = 0 To yeah.Rows.Count - 1 If yeah.Columns(0).Visible = True Then If yeah.Rows(i).Cells(0).Value Is Nothing Then strLine = (strLine & " ") + Convert.ToChar(9) Else strLine = strLine + yeah.Rows(i).Cells(0).Value.ToString() + Convert.ToChar(9) End If End If For j As Integer = 1 To yeah.Columns.Count - 1 If yeah.Columns(j).Visible = True Then If yeah.Rows(i).Cells(j).Value Is Nothing Then strLine = (strLine & " ") + Convert.ToChar(9) Else Dim rowstr As String = "" rowstr = yeah.Rows(i).Cells(j).Value.ToString() If rowstr.IndexOf(vbCr & vbLf) > 0 Then rowstr = rowstr.Replace(vbCr & vbLf, " ") End If If rowstr.IndexOf(vbTab) > 0 Then rowstr = rowstr.Replace(vbTab, " ") End If strLine = strLine + rowstr + Convert.ToChar(9) End If End If Next objStreamWriter.WriteLine(strLine) strLine = "" Next objStreamWriter.Close() objFileStream.Close() MessageBox.Show(Me, "保存EXCEL成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End Sub
回复 点赞
JirlangLianHongCh 2014年01月19日
Dim yeah As Object If Tab1.SelectedTab.Name = "T1" Then yeah = DG3 ElseIf Tab1.SelectedTab.Name = "T3" Then yeah = DG1 ElseIf Tab1.SelectedTab.Name = "T2" Then yeah = DG2 End If Dim fileName As String Dim kk As New OpenFileDialog() kk.Filter = "Excle文件(*.xls)|*.xls" If kk.ShowDialog() = DialogResult.OK Then fileName = kk.FileName Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & fileName & "';Extended Properties=Excel 8.0;" Dim dr As New DataTable Dim da As New OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn) Try da.Fill(dr) yeah.DataSource = dr Catch ex As Exception MsgBox(ex.Message.ToString) End Try End If End Sub
回复 点赞
发动态
发帖子
VB
创建于2007-09-28

1.1w+

社区成员

11.0w+

社区内容

VB技术相关讨论,主要为经典vb,即VB6.0
社区公告
暂无公告