壹佰网|ERP100 - 企业信息化知识门户

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1683|回复: 6

[Domino管理] [转帖]LotusScript提高

[复制链接]
发表于 2003/3/25 11:12:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622  。

您需要 登录 才可以下载或查看,没有帐号?注册

x
LotusScript提高
  LotusScript 是完全面向对象的编程语言。它通过预定义的类与 Domino 接口。Domino 监控用户代码的编译和加载,并且自动包含 Domino 的类定义。
  访问现有的对象最好使用 LotusScript,例如:根据其他文档的值来更改一个文档中的值。LotusScript 提供了一些公式没有的功能,例如:操作数据库存取控制列表 (ACL) 的能力。
  写script关键是取对象,查看对象的属性,所以你要学会看notes提供的Script帮助。下面是我收集的一些script例子。一般是比较技巧的程序。
 
焧ab怎样判断视图中没有文档?
焧ab如何将查询结果放到一个文件夹里?
焧ab如何删掉数据库中所有私有视图?
焧ab如何在Notes中调用ODBC数据源中的进程?
焧ab从后台刷新当前文档?
焧ab获得当前视图中选择了的文档?
焧abnotes和Excel交换数据
焧ab在视图中怎样历遍所有的文档?
焧ab在script中如何调用公式
焧ab怎样用script代理取到CGI变量
焧ab如何使用Win32API隐藏菜单呢?
焧ab怎样判断一个RTF为空值
焧ab怎样返回一个数据的类型
焧ab怎样判断一个文件目录是否存在
焧ab怎样在lotusScript中运行代理
焧ab怎样才能得到当前数据库的文件路径
焧ab怎样比较两个日期型的域
焧ab在Script中做到@mailsend
焧ab怎样用lotusScript启动附件
焧ab怎样在lotusScript中创建一个姓名域、读者域、作者域
焧ab修改了主文档后,怎样自动修改答复文档
焧ab怎样及时取到服务器的时间
焧ablotusscripts中怎样在字符串里加回车?
焧ab怎样屏蔽用户用Delete键删除文件

怎样判断视图中没有文档?
 
set doc = vw.getfirstdocument()
 if doc is nothing then
.....

 end if


如何将查询结果放到一个文件夹里?
 
下面是将搜索结果放到名叫newfolder的文件夹中,并跳转到该文件夹上
Sub Click(Source As Button) 
Dim docs As notesdocumentcollection         
Dim doc As notesdocument
...........
q=doc.query(0)
Set docs = db.ftsearch(q, 0)
Call docs.PutAllInFolder( \"newfolder\" )
Call w.OpenDatabase( \"\",\"\",\"newfolder\")
End Sub
 
如何删掉数据库中所有私有视图?
 
Dim session As New notessession 
     Dim db As notesdatabase 
     Dim doc As notesdocument 
     Set db=session.currentdatabase 
     Forall i In db.views 
     Set doc=db.getDocumentByUNID(v.universalID) 
     \' 这个地方视图当作文档来处理,以便取到视图的一些属性。 
     viewflag=doc.getItemvalue(\"$flags\") 
     If viewflag(0)=\"pYV\" Then 
     \' 视图属性中$flags为\"pYV\"的是私有视图。 
          Call i.remove 
     End If 
     End Forall
 
如何在Notes中调用ODBC数据源中的进程?
 
下面是一个利用ODBC调用access数据库(资料库)的script代码
 
Dim session As New NotesSession
Dim con As New ODBCConnection
Dim qry As New ODBCQuery
Dim result As New ODBCResultSet
Set qry.Connection = con
Set result.Query = qry
con.ConnectTo(\"资料库\")
qry.SQL = \"SELECT * FROM 资料库\"
result.Execute
If result.IsResultSetAvailable Then
Do
result.NextRow
id=result.GetValue(\"ID\",id)
Loop Until result.IsEndOfData
result.Close(DB_CLOSE)
Else
Messagebox \"Cannot get result set for AssetData\"
Exit Sub
End If
con.Disconnect
End Sub
 
从后台刷新当前文档?
 
将当前文档先关闭后再打开
set doc=uidoc.document
......
call uidoc.save()
call uidoc.close()
set uidoc=ws.editdocument(doc)

获得当前视图中选择了的文档?
 
可以用 Notesdatabase 的 Unprocesseddocuments 属性。

   Dim session As New notessession
   Dim db As notesdatabase
   Dim collection As notesdocumentcollection
  
   Set db = session.currentdatabase
   Set collection = db.UnprocessedDocuments

Unprocesseddocuments 其实很有用的
 
notes和Excel交换数据
 
Dim session As New NotesSession
   Dim db As NotesDatabase
   Dim view As NotesView
   Dim doc As NotesDocument
   Dim excelApplication As Variant
   Dim excelWorkbook As Variant
   Dim excelSheet As Variant
   Dim i As Integer
   
   Set excelApplication = CreateObject(\"Excel.Application\")
   excelApplication.Visible = True
   Set excelWorkbook = excelApplication.Workbooks.Add
   Set excelSheet = excelWorkbook.Worksheets(\"Sheet1\")
   excelSheet.Cells(1,1).Value = \"姓名\"
   excelSheet.Cells(1,2).Value = \"年龄\"
   
   i = 1
   Set db = session.CurrentDatabase
   Set view = db.GetView(\"abc\")
   Set doc = view.GetFirstDocument
   While Not(doc Is Nothing)
     i = i + 1
     excelSheet.Cells(i,1).Value = doc.ClassCategories(0)
     excelSheet.Cells(i,2).Value = doc.Subject(0)
     Set doc = view.GetNextDocument(doc)
   Wend
   excelSheet.Columns(\"A:B\").Select
   excelSheet.Columns(\"A:B\").EntireColumn.AutoFit
   
   excelWorkbook.SaveAs(\"Script 内容\")
   excelApplication.Quit
   Set excelApplication = Nothing  
   
在视图中怎样历遍所有的文档?
 
Dim db As New NotesDatabase( \"Ankara\", \"current\\projects.nsf\" )
Dim view As NotesView
Dim doc As NotesDocument
Set view = db.GetView( \"Open\\By Due Date\" )
Set doc = view.GetFirstDocument
While Not ( doc Is Nothing )
....................
 Set doc = view.GetNextDocument( doc )
Wend
 
在scipt中如何调用公式

例如我们想要取服务器名的普通名,在script中用@name() ,假设server变量以取到服务器名称
 
在script中用Evaluate可以运行公式,如:servername=Evaluate(\"@name([CN];server)\")
 

怎样用script代理取到CGI变量

Dim session As New NotesSession
Dim doc As NotesDocument
Set doc = session.DocumentContext
Messagebox \"User = \" + doc.Remote_User(0)
 
如何使用Win32API隐藏菜单呢?
 
1. Declarations :

Declare Function GetActiveWindow Lib \"user32.dll\" () As Long
Declare Function SetMenu Lib \"user32.dll\" ( Byval hmenu As Long, Byval newmenu As Long ) As Integer

2.
Sub HiddenMenu()

Dim hwnd As Long
hwnd = GetActiveWindow()
Call SetMenu(hwnd,0)

End Sub 

怎样判断一个RTF为空值
 
Function IsRTFNull(rtfield As String) As Integer  
 On Error Goto Errhandle   
 Dim workspace As New NotesUIWorkspace
 Dim uidoc As NotesUIDocument 
 Set uidoc = workspace.CurrentDocument  
 currentfield = uidoc.CurrentField  
 Call uidoc.GotoField(rtfield) 
 Call uidoc.SelectAll
 Call uidoc.DeselectAll  
 If currentfield <> \"\" Then  
 Call uidoc.GotoField(currentfield) 
 End If  
 IsRTFNull = False   
 Exit Function     
 Errhandle: 
  Select Case Err
  Case 4407
  \'the DeselectAll line generated an error message, indicating that the rich text field does   not contain anything
  If currentfield <> \"\" Then   
  Call uidoc.GotoField(currentfield)  
  End If
  IsRTFNull = True 
  Exit Function 
  Case Else
  \'For any other error, force the same error to cause LotusScript to do the error handling
  Error Err 
  End Select
  End Function
 
怎样返回一个数据的类型
 
Declarations
Class ReturnObj
 Private m_stName As String
 Private m_stType As String
  
 Property Get NameVal As String
  NameVal = m_stName$
 End Property
  
 Property Get TypeVal As String
  TypeVal = m_stType$
 End Property
  
 Sub new( arg_stName$, arg_stType$ )
  m_stName = arg_stName$
  m_stType = arg_stType
 End Sub 
End Class

Function Test() As ReturnObj
 Set Test = New ReturnObj( \"Name\", \"Type\" )
End Function

Initialize
 Dim var
 Set var = Test()
 Msgbox( var.NameVal )

 

怎样判断一个文件目录是否存在

If Dir$(dirName, ATTR_DIRECTORY) = \"\"
Then   \'Directory does not exist
Else
   \'Directory does exist
End If
 
怎样在lotusScript中运行代理

Set s = CreateObject(\"Notes.NotesSession\") 
Set db = s.GETDATABASE(\"\", \"db.nsf\")
 Set a = db.GETAGENT(\"SomeAgent\")
 Call s.SETENVIRONMENTVAR(\"AgentDocID\", \"ABCD\") 
 Call a.RUN
 
怎样才能得到当前数据库的文件路径
 
Public Function
 GetDatabasePath( db As Notesdatabase ) As String
 Dim position As Integer
 position = Instr( db.FilePath, db.FileName )
 GetDatabasePath = Left( db.FilePath , position - 1 )
End Function
 
怎样比较两个日期型的域

mdate1V = document.DateField1(0)
mdate2V = document.DateField2(0)
If mdate1V < mdate2V Then 
  MsgBox \"DATE 1 LESS THEN DATE 2\"
  Else
  MsgBox \"DATE 2 LESS THEN OR EQUAL TO DATE 1\"
End If
 
在Script中做到@mailsend
 
Function SendMailMemo(sendTo As String, _
           cc As String, _
           bcc As String, _
           subject As String, _
           body As String, _
           linkTo As NotesDocument) As Integer
 On Error Goto ErrorHandler
 Dim mailDb As New NotesDatabase(\"\", \"\")
 Dim mailDoc As NotesDocument
 Dim rtItem As NotesRichTextItem

 Call mailDb.OpenMail
 If (mailDb.IsOpen = False) Then Call mailDb.Open(\"\", \"\")
 Set mailDoc = mailDb.CreateDocument
 mailDoc.Form = \"Memo\"
 mailDoc.SendTo = sendTo
 mailDoc.CC = cc
 mailDoc.BCC = bcc
 mailDoc.Subject = subject
 Set rtItem = mailDoc.CreateRichTextItem(\"Body\")
 Call rtItem.AppendText(body)
 If Not(linkTo Is Nothing) Then
  Call rtItem.AddNewLine(2)
  Call rtItem.AppendDocLink(linkTo, \"Double-click to open document\")
 End If
 Call mailDoc.Send(False)
 SendMailMemo = True
 Exit Function

ErrorHandler:
 Print \"Error \" & Str$(Err) & \": \" & Error$
 Resume TheEnd

TheEnd:
 SendMailMemo = False
End Function

怎样用lotusScript启动附件
 
首先使用EmbeddedObjects类将附件拆离到一个临时文件夹里,然后用shell命令语句运行它

怎样在lotusScript中创建一个姓名域、读者域、作者域

创建一个\"specialType\"姓名域
 Dim variableName As New NotesItem( notesDocument, name$, value [,specialType%])
创建一个\"Author\"作者域
 Dim TAuthor As New NotesItem(doc, \"Author\", Auths, AUTHORS)
TAuthor.IsSummary = True
 

修改了主文档后,怎样自动修改答复文档
 
Sub QuerySave(Source As Notesuidocument, Continue As Variant)
 Dim Collection As NotesDocumentCollection
 Dim Doc As NotesDocument
 Dim Form, ParentStatus, Status As String   
 Set Doc = Source.Document
 Set Collection = Doc.Responses 
 Set Doc = Collection.GetFirstDocument
 ParentStatus = Source.FieldGetText(\"STATUS\") 
While Not ( Doc Is Nothing )
  Form = Doc.GetItemValue(\"Form\")(0)  
  Status = Doc.GetItemValue(\"Status\")(0)
  If (Form = \"TASK\")And (Status <> ParentStatus) Then
   Call Doc.ReplaceItemValue( \"STATUS\", ParentStatus )
   Call Doc.Save (True, False)  
  End If
  Set Doc = Collection.GetNextDocument(Doc) 
  WendEnd
Sub
 
怎样及时取到服务器的时间
 
dim doc as notesdocument
set doc = Serverdb.Createdocument
createDate = doc.Created
............
最后不要让该文档存盘

lotusScripts中怎样在字符串里加回车?

\"aaa\"+chr(10)+\"bbb\" 
 

怎样屏蔽用户用Delete键删除文件
 
在数据库Script中的Querydocumentdelete中使用下列语句。
Continue=False
发表于 2003/3/25 15:15:25 | 显示全部楼层
现收藏再说
发表于 2003/3/25 15:25:10 | 显示全部楼层
不错
发表于 2003/3/26 09:36:50 | 显示全部楼层
非常经典,非常精彩。
发表于 2003/3/26 10:00:36 | 显示全部楼层
收藏!~
发表于 2003/7/10 20:51:56 | 显示全部楼层
先谢了,再问一句,哪里弄的这些好东东
要授之以渔嘛!/道谢
发表于 2003/7/11 09:28:47 | 显示全部楼层
这个原贴很久以前就有的了,什么地方可以看到原贴我可要想想!/害羞
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|手机版|壹佰网 ERP100 ( 京ICP备19053597号-2 )

Copyright © 2005-2012 北京海之大网络技术有限责任公司 服务器托管由互联互通
手机:13911575376
网站技术点击发送消息给对方83569622   广告&合作 点击发送消息给对方27675401   点击发送消息给对方634043306   咨询及人才点击发送消息给对方138011526

GMT+8, 2025/11/29 14:38 , Processed in 0.025709 second(s), 14 queries , File On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表