不是没有人会,而是你说的根本就是开玩笑的
database=d:\account.xls,就是算修改成直接写到客户端,难道你每个客户端都共享出一个可读写的目录出来?而且,所有的客户端保持一致?
这种部署不是开玩笑嘛!
直接使用Recordset导出即可,不知道你使用的什么语言,给你一个VB的实例
引用自:http://blog.sina.com.cn/s/blog_4882a26b01000c0t.html
Option Explicit
'把数据传输进Excel,DataObject为数据源,FirstCol从第几列开始(有可能第一列不导出),ColType哪些列不是文字
'调用的时候,IF OutPutToExcel(sRecordset, 1, "1,2,3") THEN Msgbox "OK"
Public Function OutPutToExcel(DataObject As Object, FirstCol As Integer, ColType As String) As Boolean
ColType = Replace(ColType, " ", "")
If Right(ColType, 1) <> "," Then ColType = ColType & ","
If Left(ColType, 1) <> "," Then ColType = "," & ColType
OutPutToExcel = False
On Error GoTo ErrorSendExcel
If DataObject Is Nothing Then
MsgBox "没有可以导出的数据!"
Exit Function
ElseIf DataObject.RecordCount < 1 Then
MsgBox "没有可以导出的数据!"
Exit Function
Else
Dim OutPutExcel As Object
Dim ExSheet As Object
Dim ExwBook As Object
Dim i As Integer
Dim j As Integer
Dim z As Integer
Set OutPutExcel = CreateObject("Excel.Application")
Set ExwBook = Nothing
Set ExSheet = Nothing
Set ExwBook = OutPutExcel.Workbooks().Add
Set ExSheet = ExwBook.Worksheets("sheet1")
z = DataObject.Fields.Count - 1
With DataObject
.MoveFirst
For i = 0 To DataObject.RecordCount
If i = 0 Then
For j = FirstCol To z
If j >= 26 Then
OutPutExcel.Range(Chr(65) & Chr(64 + j - 26 + 1) & i + 1).NumberFormat = "@"
OutPutExcel.Range(Chr(65) & Chr(64 + j - 26 + 1) & i + 1).Value = DataObject.Fields(j).Name
Else
OutPutExcel.Range(Chr(64 + j + 1) & i + 1).NumberFormat = "@"
OutPutExcel.Range(Chr(64 + j + 1) & i + 1).Value = DataObject.Fields(j).Name
End If
Next
Else
For j = FirstCol To z
If j >= 26 Then
If InStr(ColType, "," & CStr(j) & ",") = 0 Then
OutPutExcel.Range(Chr(65) & Chr(64 + j - 26 + 1) & i + 1).NumberFormat = "@"
End If
OutPutExcel.Range(Chr(65) & Chr(64 + j - 26 + 1) & i + 1).Value = CStr(DataObject.Fields(j).Value & "")
Else
If InStr(ColType, "," & CStr(j) & ",") = 0 Then
OutPutExcel.Range(Chr(64 + j + 1) & i + 1).NumberFormat = "@"
End If
OutPutExcel.Range(Chr(64 + j + 1) & i + 1).Value = CStr(DataObject.Fields(j).Value & "")
End If
Next
.MoveNext
End If
Next
OutPutExcel.ActiveSheet.Cells.Select
OutPutExcel.selection.Columns.AutoFit
OutPutExcel.ActiveSheet.Range("A1").Select
OutPutExcel.Visible = True
End With
End If
MsgBox "数据导出完毕!"
OutPutToExcel = True
Set OutPutExcel = Nothing
Set ExSheet = Nothing
Set ExwBook = Nothing
Exit Function
ErrorSendExcel:
MsgBox "导出数据出错,错误提示:" & Err.Description
OutPutToExcel = False
Set OutPutExcel = Nothing
Set ExSheet = Nothing
Set ExwBook = Nothing
Exit Function
End Function
直接导出到客户端基本不可能,因为vbscript是服务器脚本,而你用客户端脚本却又不能读取远程数据库.
有一种简单的方法:
你先把它导出到服务器(要在网站目录里),然后提供一个页面让用户下载或是导出后直接用
response.redirect "文件地址"
等用户下载完后删除
还有一种就是不知道行不行,没试过:
先用VB建一个dll(能读取远程数据库的),然后让客户端使用此Activex控件(还可以选择目录进行保存).
localhost代表的是本地IP,你的问题是服务器就建在本机上!
在客户端建个共享可写的目录,然后导出到\\client\shareFolder\account.xls
d:\换成服务器网络上的地址