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

juning 2004-08-11 05:54:36
用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
%>
...全文
111 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
albertbanda 2004-08-16
  • 打赏
  • 举报
回复
直接就是xlApp.Visible =True
catch in touch with me like this: albertbanda2000@yahoo.com.cn
juning 2004-08-11
  • 打赏
  • 举报
回复
我已經把xlApp.Application.Visible = True 改成了xlapp.visible=true
但是仍然不能出現EXCEL。怎么回事啊﹖
服务器端不能有可见窗口是什么意思 哦﹖
hhjjhjhj 2004-08-11
  • 打赏
  • 举报
回复
服务器端不能有可见窗口。
jackyhyoung 2004-08-11
  • 打赏
  • 举报
回复
xlApp.Application.Visible = True
'''''''''''''''
msitake:
xlapp.visible=true
repqo 2004-08-11
  • 打赏
  • 举报
回复
excel.Visible = true
Free Spire.XLS for .NET 是e-iceblue公司开发的一款支持对所有Excel格式类型文件进行操作的.NET 控件。它适用于任何类型的应用程序比如ASP.NET Web应用程序或者Windows桌面应用程序。Spire.XLS for .NET允许开发人员创建和管理Excel,而不需要安装Microsoft Excel或者Microsoft Office。相比Microsoft,Spire.XLS for .NET对于开发人员来说是一个更好的选择 - 自动化,安全,稳定,可扩展性延伸,速度快,价格便宜和功能强大。 通过使用Free Spire.XLS for .NET,开发人员可以快速方便的查看,生成,读写以及自定义编辑Excel文件。Spire.XLS for .NET支持Excel 97-2003, Excel 2007, Excel 2010 and Excel 2013。它还支持C#, VB.NET, ASP.NET和 ASP.NET MVC编程语言 作为一款专业,强大,方便易用的控件,Spire.XLS for .NET有一下主要功能: 新建Excel文件,编辑已有的Excel文件,多种保存Excel方式,设置Excel文件属性,文件打印设置,合并,拆分或者拷贝单元格,支持对Excel文件加锁或者加密保护。 Spire.XLS for .NET支持把数据从数据库导出到Excel工作表,或者把数据从Excel数据导入到数据库。 Spire.XLS for .NET 提供强大的功能为开发者设置单元格格式。这次格式化数字,文字缩进,定位调整,设置单元格边线,单元格填充以及保护等。 开发人员可以轻松的利用Spire.XLS for .NET向Excel文件里面写入内容,包括超过530多种的公式,70多种表格,支持插入图片,不同类型的文字,链接,注释甚至VBA等。 Spire.XLS for .NET 还允许开发人员将Excel文件转换成PDF, HTML, CSV, Text, XML以及图片格式。 注:下载包含有Spire.xls.dll文件以及部分Demo, 你可以调用DLL并参照Demo提供的代码处理Excel文档。

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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