久久―日本道色综合久久,亚洲欧美精品在线,狼狼色丁香久久婷婷综合五月,香蕉人人超,日本网站黄,国产在线观看不卡免费高清,无遮挡的毛片免费

2023信創(chuàng)獨(dú)角獸企業(yè)100強(qiáng)
全世界各行各業(yè)聯(lián)合起來,internet一定要實(shí)現(xiàn)!

導(dǎo)出EXCEL/FOXPRO/PRODOX格式表

2004-02-12 eNet&Ciweek

  一般是在ACCESS或是SQLSERVER中查尋,或是匯總,然后生成一個(gè)‘記錄集’可以顯示在GRID里,也可以將這個(gè)記錄集導(dǎo)出到磁盤中。  

  下面可以導(dǎo)出Xls,DBF,DB,MDB(表),這些功能是由ISAM數(shù)據(jù)庫(kù)接口實(shí)現(xiàn),為了導(dǎo)出各種版本的文件,我在MS網(wǎng)站了最新的JET4和MDAC6。前者到用于桌面數(shù)據(jù)庫(kù)如ACCESS,F(xiàn)OXPRO的組件,后者是實(shí)現(xiàn)新版本ADO組件。分別在:

  http://download.microsoft.com/download/access2000/SP/4.0/NT5/EN-US/Jet40SP5_W2K.exe
  http://download.microsoft.com/download/dasdk/install/2.60.6526.3/WIN98Me/CN/mdac_typ.exe

  這些是標(biāo)準(zhǔn)的SQL導(dǎo)出語(yǔ)句:

  select * into [Excel 8.0;database=導(dǎo)出目錄].導(dǎo)出表名 from 表

  select * into [FoxPro 2.6;database=導(dǎo)出目錄].導(dǎo)出表名 from 表

  select * into [FoxPro 2.5;database=同上].導(dǎo)出表名 from 表

  select * into [dBase III;database=同上].導(dǎo)出表名 from 表

  select * into [Paradox 4.X;database=同上].導(dǎo)出表名 from 表

  select * into [;database=C:\temp\xxx.mdb].導(dǎo)出表名 from 表

  下面程序?yàn)閷?shí)現(xiàn)用戶自定議文件名用變量代替一部分。

  http://go.163.com/~chunpeng/project/export.jpg

  http://go.163.com/~chunpeng/project/Export.zip 點(diǎn)這里原程序文件?! ?

  '請(qǐng)先引用ADODB類庫(kù)。

  Dim Export_Str, mdbTable As String

  Dim rsExport As New ADODB.Recordset

  Dim conn As New ADODB.Connection

  Private Sub Close_cmd_Click()

  Unload Me

  End Sub

  

  Private Sub EXport_cmd_Click()

  Dim myPath, myStr As String, myPos As Integer

  '******************處理選擇的各種表的導(dǎo)出

  With Dialog1

  If myOption(2).Value Then

  .FilterIndex = 1

  .ShowSave

  myStr = StrReverse(.FileName) '串取反

  myPos = InStr(myStr, "\") '在反字符串中,找從左開始第一個(gè)\的位置

  On Error GoTo myError '防FILENAME為空,MID出錯(cuò)

  myPath = StrReverse(Mid(myStr, myPos)) '取目錄部分,并還原.

  myStr = StrReverse(Left(myStr, myPos - 1)) '取文件名

  Export_Str = "select * into [dBase III;database=" & myPath & "]." & myStr & " from Customers"

  .DefaultExt = "*.DBF"
  

  ElseIf myOption(3).Value Then

  mdbTable = InputBox("請(qǐng)給導(dǎo)出到MDB文件的表確定表名")

  .FilterIndex = 2

  .ShowSave

  Export_Str = "select * into [;database=" & .FileName & "]." & mdbTable & " from Customers"

  .DefaultExt = "*.MDB" 

  ElseIf myOption(4).Value Then

  .FilterIndex = 3

  .ShowSave

  Export_Str = "select * into [Excel 8.0;database=" & .FileName & "].Customers from Customers"

  .DefaultExt = "*.XLS"  

  ElseIf myOption(5).Value Then

  .FilterIndex = 4

  .ShowSave

  myStr = StrReverse(.FileName) '串取反

  myPos = InStr(myStr, "\") '在反字符串中,找從左開始第一個(gè)\的位置

  On Error GoTo myError '防FILENAME為空,MID出錯(cuò)

  myPath = StrReverse(Mid(myStr, myPos)) '取目錄部分,并還原.

  myStr = StrReverse(Left(myStr, myPos - 1)) '取文件名

  Export_Str = "select * into [Paradox 4.X;database=" & myPath & "]." & myStr & " from Customers"

  .DefaultExt = "*.DB"

  End If

  End With
  

  '*****生成文件

  Debug.Print Export_Str

  If rsExport.State = 1 Then

  rsExport.Close

  End If 

  If Dir(Dialog1.FileName) <> "" Then

  On Error GoTo myError '防用戶沒選文件

  If Dialog1.FilterIndex <> 2 Then

  Kill (Dialog1.FileName)

  End If

  rsExport.Open Export_Str, conn, adOpenStatic, adLockOptimistic

  Else

  rsExport.Open Export_Str, conn, adOpenStatic, adLockOptimistic

  End If

  myError:

  Exit Sub

  End Sub  

  Private Sub Form_Load()

  '聯(lián)接數(shù)據(jù)庫(kù)并打開記錄集

  conn.CursorLocation = adUseServer

  conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\NWind.mdb;"

  rsExport.Open "select *from Customers", conn, adOpenStatic, adLockOptimistic

  Set Grid1.DataSource = rsExport

  '初始化對(duì)話筐

  With Dialog1

  .Filter = "FoxBase/FoxPro (*.DBF) *.DBF Access 8.0(*.MDB) *.MDB Excel 8.0(*.XLS) *.XLS Paradox 4.x(*.DB) *.DB"

  .DialogTitle = "導(dǎo)出文件為"

  .CancelError = False

  End With

  End Sub

相關(guān)頻道: eNews

您對(duì)本文或本站有任何意見,請(qǐng)?jiān)谙路教峤?,謝謝!

投稿信箱:tougao@enet16.com