最简单的办法
在DOS命令行下执行
bcp pubs..bitmap out c:\bitmap.xls -Sservername -Usa -Ppassword
pus---db name
bitmap--table name
-Sservername在本机可省
-U用户名,一般SA的password为空
在DOS命令行下执行
bcp pubs..bitmap out c:\bitmap.xls -Sservername -Usa -Ppassword
pus---db name
bitmap--table name
-Sservername在本机可省
-U用户名,一般SA的password为空
可写
bcp pubs..bitmap out c:\bitmap.xls -c -Sservername -Usa -Ppassword
进入企业管理器
找到要倒出的表
选择所有任务/倒出数据
点击下一步
选择当前数据库为数据源,选择数据库验证 输入口令和密码
在目标内选择microsoftexcel97-2000
在文件内选择要导入的文件名 如 Book2.xls
下一步
在数据源内选择要倒出的表
在目标内选择要导入的excel 的工作表 如Sheet1$
下一步
完成
打开excel文件可以看到数据已经导入进出
2.利用excel的导入功能也可以实现
要自己做好数据源,导入
'在模块中输入下面的代码
'首先在电脑中新建一个EXCEL的模块文件。
'recordset 是VB中的记录集; filename EXCEL的模块文件名;DataGrid 是数据表
Public Sub reportexcel(recordset As recordset, filename As String, DataGrid As DataGrid)
Dim xlApp As Excel.Application
Dim xlSheet As Excel.Worksheet
MousePointer = 99
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(App.Path & "\" & filename, updatelinks)
Set xlSheet = xlBook.Worksheets(1)
xlApp.Visible = True
Dim X As Integer
Dim Y As Integer
Dim mt As String
Dim novisible As Integer, yesvisible As Integer
Y = recordset.RecordCount
X = recordset.Fields.Count
recordset.MoveFirst
For j = 1 To X
If DataGrid.Columns(j - 1).Visible = True And DataGrid.Columns(j - 1).Width <> 0 Then
yesvisible = j - novisible
xlSheet.Cells(1, yesvisible) = recordset.Fields(j - 1).Name
For i = 1 To Y
xlSheet.Cells(i + 1, yesvisible) = recordset.Fields(j - 1).Value
recordset.MoveNext
Next
recordset.MoveFirst
Else
novisible = novisible + 1
End If
Next
'xlApp.WindowState = xlMinimized
'xlApp.SendKeys "%fa"
'xlApp.SendKeys "app.path & 套件导出.xls"
'xlApp.SendKeys "%S"
Set x1app = Nothing
'Me.SetFocus
MousePointer = 0
End Sub在窗体中输入下面的代码:(新建一个按钮)
Private Sub command1_Click()
call reportexcel(recordset As recordset, filename As String, DataGrid As DataGrid)
End Sub