关于如何使用sql语句查询excel。
如何使用sql查询语句查询,lkl.xls中的表一,将结果放在表二中。
请各位老师指点一下,谢谢了。
[解决办法]
导出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