不好意思,写错了,重来'Irowcount 行数 'Icolcount 列数With Sheet1 .Range(.Cells(1, 1), .Cells(Irowcount, Icolcount)).Font.strikethrough = True End With
'請你自己加個CommonDialog控件 Private Sub Command3_Click() Dim objFileSystem As Object Dim objExcelText As Object Dim strTableString As String, i As Integer, strFileName As String Dim pubConn As New ADODB.Connection Dim rsTable As New ADODB.Recordset Dim strConn As String Dim strSQL As String strConn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=develop; password=12345;Data Source=ServerNmae" pubConn.Open strConn rsTable.CursorLocation = adUseClient strSQL = "select top 10 * from gate_register" rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic
For i = 0 To rsTable.Fields.Count - 1 strTableString = strTableString & rsTable.Fields(i).Name & Chr(9) '獲取字段名 Next strTableString = strTableString & rsTable.GetString '字段名+數據庫的記錄
'Icolcount 列数Sheet1.Range(.Cells(1, 1), .Cells(Irowcount, Icolcount)).Font.strikethrough = True
'Icolcount 列数With Sheet1
.Range(.Cells(1, 1), .Cells(Irowcount, Icolcount)).Font.strikethrough = True
End With
Private Sub Command3_Click()
Dim objFileSystem As Object
Dim objExcelText As Object
Dim strTableString As String, i As Integer, strFileName As String
Dim pubConn As New ADODB.Connection
Dim rsTable As New ADODB.Recordset
Dim strConn As String
Dim strSQL As String strConn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=develop; password=12345;Data Source=ServerNmae"
pubConn.Open strConn
rsTable.CursorLocation = adUseClient
strSQL = "select top 10 * from gate_register"
rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic
For i = 0 To rsTable.Fields.Count - 1
strTableString = strTableString & rsTable.Fields(i).Name & Chr(9) '獲取字段名
Next
strTableString = strTableString & rsTable.GetString '字段名+數據庫的記錄
cmDialog.CancelError = False
cmDialog.FileName = "FileName" '默認生成的文件名
cmDialog.DialogTitle = "Save Export File"
cmDialog.Filter = "Excel (*.xls)|*.xls|文本文件(*.DBF)|*.DBF|檔案文件(*.doc)|*.doc|所有文件(*.*)|*.*"
cmDialog.DefaultExt = "*.xls"
cmDialog.ShowSave
strFileName = cmDialog.FileName
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objExcelText = objFileSystem.createtextfile(strFileName, True)
objExcelText.writeline (strTableString)
objExcelText.Close
Set objFileSystem = Nothing
End Sub