当前位置:软件学习 > 其它软件 >>

Excel导出不能连续执行问题(RunOnServer)

设计一Button,用户点击后代理在服务器端运行

代理运行完成后会将Excel存档在服务器,并发Mail给用户

目前问题是:用户第一次点击能成功执行,以后就不可以咯,需重新登录Notes或等待10分钟左右才能执行成功

服务器端提示错误为:Cannot create automatic object

这是什么问题,代码是否需要断开与服务器连接,如何操作,期待高手解决 --------------------编程问答-------------------- 貌似是第一次操作成功以后应该把内存中的东西给关掉之类的东西;不知道你对session了不了解,正常使用完session之后应该把session关掉,如果不关掉要等到session超时之后它才会自动关闭;个人感觉你的程序貌似跟关session有点类似,至于你具体该怎么操作我就不清楚了,你再找找好好看看你的程序吧,或者调试一下,应该是能发现问题的!! --------------------编程问答-------------------- BS还是CS?如果是BS的话,需要检查一下你的代码,在CS下使用的Office API是不能在BS下用的 --------------------编程问答-------------------- Button:
Sub Click(Source As Navigator)
Dim uiws As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Set db = session.CurrentDatabase

Dim DBoxDoc As NotesDocument
Set DBoxDoc = New NotesDocument(db)

If uiws.DialogBox( "DialogBox-QueryQTY", True,True, False, False, False, False,"客戶代碼",DBoxDoc) Then

Const Macro$ = "@Name([Abbreviate]; @UserName)"
txtItem = Evaluate(Macro$)
UserName = Ucase(Cstr(txtItem(0)))

Dim SetupView As NotesView
Dim SetupDoc As NotesDocument     
Set SetupView = db.GetView("View-SystemSetup")
Set SetupDoc=SetupView.GetDocumentByKey("Form-SystemSetup") 

SetupDoc.TempCustCode = DBoxDoc.CusCode(0)
SetupDoc.UserName = UserName
Call SetupDoc.save(True,True)

Dim agent As NotesAgent
Set agent = db.GetAgent("(GetEPIQTY)")
If agent.RunOnServer = 0 Then
Messagebox  "客戶'"+DBoxDoc.CusCode(0)+"'對賬數據導出成功,請至郵箱收取"
Else
Messagebox "數據導出失敗"
End If
End If

End Sub --------------------编程问答-------------------- Sub Initialize
Dim session As New NotesSession
Dim agent As NotesAgent
Set agent = session.CurrentAgent
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim Con As New ODBCConnection

Dim SetupView As NotesView
Dim SetupDoc As NotesDocument     
Set SetupView = DB.GetView("View-SystemSetup")
Set SetupDoc=SetupView.GetDocumentByKey("Form-SystemSetup") 

Dim tstDataSource As String
Dim tstID As String
Dim tstPassword  As String
tstDataSource = SetupDoc.DS(0)
tstID = SetupDoc.user(0)
tstPassword = SetupDoc.pwd(0)

RetCode% = Con.ConnectTo(tstDataSource, tstID, tstPassword)
If RetCode% >= 0 Then
Print "ODBC 連線失敗"
Exit Sub
End If

Dim Qry As New ODBCQuery
Set Qry.Connection = Con
Dim Res As New ODBCResultSet

Dim excelApplication As Variant
Dim excelWorkbook As Variant
Dim excelSheet As Variant
xlsFileName$ = "D:\CustEPI\CustEPIStock.xls"
Set excelApplication = CreateObject("Excel.Application") 
excelApplication.Visible = False 
Set excelWorkbook = excelApplication.Workbooks.Add
'0.Summery
If SetupDoc.TempCustCode(0) = "" Then
Qry.SQL = {SELECT PN.CUSTCODE,PN.CUSTEPI,PT.SEGMENT1,PT.POQTY,PT.WQQTY,PT.QRQTY,PT.INQTY,PT.RNQTY,PT.ITQTY,PT.OTQTY,PT.UQQTY,PT.URQTY,PT.OHQTY,
(SELECT PRODNAME.PRODNAME FROM (select distinct PDN.custcode,PDN.proqepi,getproduct(PDN.custcode,PDN.proqepi) PRODNAME
from proqmis.PRODUCT_NOTES PDN) PRODNAME
WHERE PRODNAME.CUSTCODE = PN.CUSTCODE
AND PRODNAME.PROQEPI = PN.PARTNO) PRODNAME
FROM PARTNO_TRN PT,PARTNO PN
WHERE PT.SEGMENT1 = PN.PARTNO}
Else
Qry.SQL = {SELECT PN.CUSTCODE,PN.CUSTEPI,PT.SEGMENT1,PT.POQTY,PT.WQQTY,PT.QRQTY,PT.INQTY,PT.RNQTY,PT.ITQTY,PT.OTQTY,PT.UQQTY,PT.URQTY,PT.OHQTY,
(SELECT PRODNAME.PRODNAME FROM (select distinct PDN.custcode,PDN.proqepi,getproduct(PDN.custcode,PDN.proqepi) PRODNAME
from proqmis.PRODUCT_NOTES PDN) PRODNAME
WHERE PRODNAME.CUSTCODE = PN.CUSTCODE
AND PRODNAME.PROQEPI = PN.PARTNO) PRODNAME
FROM PARTNO_TRN PT,PARTNO PN
WHERE PT.SEGMENT1 = PN.PARTNO
AND PN.CUSTCODE='}+Trim(SetupDoc.TempCustCode(0))+{'}
End If
Set Res.Query =Qry
Res.Execute

Set excelSheet = excelWorkbook.Worksheets("Sheet1") 
excelSheet.Name = "summary"
Set excelSheet = excelWorkbook.Worksheets("summary")
cnt = 1
excelSheet.Cells(cnt,1).Value = "客戶名稱"
excelSheet.Cells(cnt,2).Value = "客戶EPI料號"
excelSheet.Cells(cnt,3).Value = "ProQ EPI料號"
excelSheet.Cells(cnt,4).Value = "原始進貨量"
excelSheet.Cells(cnt,5).Value = "IQC在驗量"
excelSheet.Cells(cnt,6).Value = "IQC驗退量"
excelSheet.Cells(cnt,7).Value = "庫房原始庫存"
excelSheet.Cells(cnt,8).Value = "轉入數量"
excelSheet.Cells(cnt,9).Value = "轉出數量"
excelSheet.Cells(cnt,10).Value = "倉退量"
excelSheet.Cells(cnt,11).Value = "領用量"
excelSheet.Cells(cnt,12).Value = "領退量"
excelSheet.Cells(cnt,13).Value = "可用庫存量"
excelSheet.Cells(cnt,14).Value = "可用产品别"

While Res.NextRow
cnt = cnt + 1
excelSheet.Cells(cnt,1).Value = Res.GetValue("custcode")
excelSheet.Cells(cnt,2).Value = Res.GetValue("custepi")
excelSheet.Cells(cnt,3).Value = Res.GetValue("SEGMENT1")
excelSheet.Cells(cnt,4).Value = Res.GetValue("POQTY")
excelSheet.Cells(cnt,5).Value = Res.GetValue("WQQTY")
excelSheet.Cells(cnt,6).Value = Res.GetValue("QRQTY")
excelSheet.Cells(cnt,7).Value = Res.GetValue("INQTY")
excelSheet.Cells(cnt,8).Value = Res.GetValue("ITQTY")
excelSheet.Cells(cnt,9).Value = Res.GetValue("OTQTY")
excelSheet.Cells(cnt,10).Value = Res.GetValue("RNQTY")
excelSheet.Cells(cnt,11).Value = Res.GetValue("UQQTY")
excelSheet.Cells(cnt,12).Value = Res.GetValue("URQTY")
excelSheet.Cells(cnt,13).Value = Res.GetValue("OHQTY")
excelSheet.Cells(cnt,14).Value = Res.GetValue("PRODNAME")
Wend
...
...
...
excelApplication.DisplayAlerts = False
Call excelSheet.SaveAs(xlsFileName$)
excelApplication.Quit
Set excelApplication = Nothing

Dim rtitem As NotesRichTextItem 
Dim object As NotesEmbeddedObject
Dim memo As New NotesDocument(db)
Set rtitem = New NotesRichTextItem(memo, "Body") 
Set object = rtitem.EmbedObject(EMBED_ATTACHMENT,"",xlsFileName$)

memo.Form = "Memo"
memo.SendTo =  SetupDoc.UserName(0)   '"garcia_lin@promos.com.tw" 'session.UserName

memo.Subject = "客戶EPI對賬報表"
Call memo.Send(False)

goend:
RetCode% = Res.Close(DB_CLOSE)
RetCode%=Con.Disconnect
'End If
End Sub --------------------编程问答-------------------- 高手看看,如何断Session? --------------------编程问答-------------------- 你出错的object指的是:
Set excelApplication = CreateObject("Excel.Application") 。
excelApplication 这个对象不可用重复使用。楼主在ls结束里面,把excelApplication 进行关闭操作。
还有楼主怎么使用java来写。 --------------------编程问答-------------------- set object = nothing --------------------编程问答-------------------- Object关闭了滴也:

Set excelApplication = Nothing --------------------编程问答-------------------- excelApplication 、excelWorkbook 、excelSheet 都关闭试试看~~ --------------------编程问答-------------------- set object = nothing
object.close
补充:企业软件 ,  Lotus
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,