用VB編DLL﹐將數據導入EXCEL﹐ASP調用DLL﹐進程中有EXCEL.EXE﹐但是卻不可見。望高手指點。在線等

juning 2004-08-11 05:59:30
用VB編DLL﹐將數據導入EXCEL﹐ASP調用DLL﹐進程中有EXCEL.EXE﹐但是卻不可見。不知道為什么。望高手指點。
DLL代碼如下﹕
Public Function ExporToExcel(strsql As Variant, strcon As Variant)

Dim cn As New ADODB.Connection
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

cn.ConnectionString = strcon
cn.ConnectionTimeout = 20
cn.CommandTimeout = 600

cn.Open

With Rs_Data
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = cn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Source = strsql
.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
cn.Close

End Function

ASP調用代碼如下﹕
<%
str="Provider=SQLOLEDB.1; Persist Security Info=True; User ID=sa; Password=juning; Data Source=10.192.35.142; Initial Catalog=SQC"
strsql = "select * from tbl_user"
set ex=server.CreateObject("IEDSDLL.clsExcel")
ex.ExporToExcel strsql,str
%>
...全文
181 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
超级大笨狼 2004-08-12
  • 打赏
  • 举报
回复
xlApp.quit你忘记了
juning 2004-08-11
  • 打赏
  • 举报
回复
但是EXCEL被調用話也改出現啊﹐要不怎么看見是什么數據和進行操作﹖
-神仙- 2004-08-11
  • 打赏
  • 举报
回复
dll是进程内的,看不到是正常的。
juning 2004-08-11
  • 打赏
  • 举报
回复
請問你是怎么解決的啊﹖我的EXCEL不是關不掉﹐是它根本就沒有出來﹐只能在進程里看到有EXCEL.EXE在。
望賜教﹐謝謝﹗
yangbc 2004-08-11
  • 打赏
  • 举报
回复
今天刚解决这个问题,vb的dll操作excel比较容易,就是调试起来麻烦,这个excel.exe进程可以用程序在操作完后关闭掉,不会有大麻烦。
springRainyao 2004-08-11
  • 打赏
  • 举报
回复
这个问题没什么好的解决方法

xlApp.visable=true这句很多asp不吃,我以前做的类似的,是用客户端vbscript调的,客户端装office2000就怎么visable也不出来,后来换了个officeXP,好了~~~~

不过也不一定的事,有些机器office2000visable很正常
juning 2004-08-11
  • 打赏
  • 举报
回复
是xlApp.visable=true 吧
我DLL里面有寫啊﹗
ttt2 2004-08-11
  • 打赏
  • 举报
回复
xlApp.visabled=true

28,390

社区成员

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

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