我在vb里面将导出数据到excel写入了dll文件,请问在asp中怎么调用

zzz2002zzz 2004-08-11 05:10:22
我在调用时传了两个参数,一个是sql="select * from tbl_user",一个是数据库连接的,conn= "Provider=SQLOLEDB.1;Persist Security Info=True; User ID=sa;Password=..; Data Source=..;Initial Catalog=.." 传值是总提示类型不符,请多指教


...全文
129 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
poya00 2004-08-12
  • 打赏
  • 举报
回复
你试试把数据库连接的字符串拆开传,vb中的关键字别传,然后在vb中将字符串做连接。
zzz2002zzz 2004-08-11
  • 打赏
  • 举报
回复
我用的就是在这里看的代码


Public Function ExporToExcel(str1 as string,str2 as string)

'ExporToExcel = False
'On Error GoTo ErrHandler

Dim Rs_Data As New ADODB.Recordset
Dim Irowcount As Integer
Dim Icolcount As Integer
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlQuery As Excel.QueryTable

' Dim Conn As New Connection
' Set Conn = New ADODB.Connection
' Conn.Open str1


With Rs_Data
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = str1
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Source = str2
.Open
End With

With Rs_Data
If .RecordCount < 1 Then
MsgBox ("沒有數據記錄!")
Exit Function
End If
Irowcount = .RecordCount '記錄總數
Icolcount = .Fields.Count '字段總數
End With

Set xlApp = CreateObject("Excel.Application")
Set xlBook = Nothing
Set xlSheet = Nothing
Set xlBook = xlApp.Workbooks().Add
Set xlSheet = xlBook.Worksheets("sheet1")
xlApp.Visible = True

Set xlQuery = xlSheet.QueryTables.Add(Rs_Data, xlSheet.Range("a1"))

With xlQuery
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
End With

xlQuery.FieldNames = True
xlQuery.Refresh

With xlSheet
.Range(.Cells(1, 1), .Cells(1, Icolcount)).Font.Bold = True '字体加粗
.Range(.Cells(1, 1), .Cells(Irowcount + 1, Icolcount)).Borders.LineStyle = xlContinuous '表格邊框樣式
End With

xlApp.Application.Visible = True
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
ExporToExcel = True

'ErrHandler:
' MsgBox "(" & Err.Number & ")" & Err.Description
'
End Function
baby21st 2004-08-11
  • 打赏
  • 举报
回复
传的两个不都是String吗?
bananasmiling 2004-08-11
  • 打赏
  • 举报
回复
在vb里面将导出数据到excel写入了dll文件,??
你这个文件是如何写的..能不能贴出来看看??

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧