每一个存在于NSF数据库里面的文档都可以当做一个DXL元素,向DXL里面追加代码,就可以向文档中添加设计元素,实现一些很特别的功能

例:在rtf域里面插button
样例来自:www.nsftools.com,修改增加了javascript按钮
'RichTextButton Class:
Option Public
Option Explicit

'** possible languages we can use with SetButtonLanguage
Const RTB_LOTUSSCRIPT = 1
Const RTB_FORMULA = 2
Const RTB_JAVASCRIPT = 3
'** possible types we can use with SetEdgeType
Const RTB_SQUARE = 1
Const RTB_ROUNDED = 2
Class RichTextButton
 '** This class makes it easy to create a button that can be appended
 '** to a NotesRichTextField. Here's an example of use:
 
 '** Dim rtbutton As New RichTextButton
 '** Call rtbutton.SetLabel("Formula Button")
 '** Call rtbutton.SetButtonLanguage(RTB_FORMULA)
 '** Call rtbutton.SetCode( |@Prompt([ok]; "My Button"; "You clicked my button");| )
 '** Set rtitem = doc.GetFirstItem("Body")
 '** Call rtbutton.AppendButton(rtitem)
 
 '** version 1.2
 '** September 2, 2005
 '** Julian Robichaux -- http://www.nsftools.com
 Private label As String
 Private edgeType As Integer
 Private buttonLanguage As Integer
 Private code As String
 
 Public Sub New ()
  label = "Button"
  edgeType = RTB_ROUNDED
  buttonLanguage = RTB_JAVASCRIPT
 End Sub
 
 Public Sub SetLabel (labelText As String)
  label = labelText
 End Sub
 
 Public Sub SetEdgeType (edgeType As Integer)
  Me.edgeType = edgeType
 End Sub
 
 Public Sub SetButtonLanguage (buttonLanguage As Integer)
  Me.buttonLanguage = buttonLanguage
 End Sub
 
 Public Sub SetCode (code As String)
  Me.code = code
 End Sub
 
 Public Function XmlConvert (txt As String) As String
  '** get rid of the text characters that XML doesn't like (accented
  '** characters are usually okay, as long as you use an encoding
  '** like ISO-8859-1
  XmlConvert = txt
  XmlConvert = Replace(XmlConvert, "&", "&")
  XmlConvert = Replace(XmlConvert, "<", "&lt;")
  XmlConvert = Replace(XmlConvert, ">", "&gt;")
 End Function
 
 Function AppendButton (rtitem As NotesRichTextItem) As String
  '** This function will attempt to append a button to a given
  '** NotesRichTextItem, using code that has been assigned
  '** to this object after it has been created (using the SetCode
  '** method). The code language (as set with the SetLanguageType
  '** method) can be either LotusScript or Formula language.
  
  '** If there is an error creating the button (often because the code
  '** doesn't compile correctly), this function will return the error
  '** message. If the button is created properly, an empty string
  '** will be returned.
  On Error Goto processError
  
  '** if no rich text item was given to us, just exit without doing anything
  If (rtitem Is Nothing) Then
   Exit Function
  End If
  
  Dim session As New NotesSession
  Dim db As NotesDatabase
  Dim doc As NotesDocument
  Dim body As NotesRichTextItem
  Dim importer As NotesDXLImporter
  
  Dim buttonCode As String
  Dim buttonTag As String
  Dim dxl As String
  Dim codeStr As String
  codeStr = "<code event='click'>"
  '** LotusScript和Formula的<code>代码
  '** set up the DXL to be used for the code in the button
  
  Select Case buttonLanguage
  Case RTB_LOTUSSCRIPT
   buttonCode = |<lotusscript>Sub Click(Source As Button)
| & XmlConvert(code) & |
End Sub</lotusscript>|  
  Case RTB_FORMULA
   buttonCode = |<formula>| & XmlConvert(code) & |</formula>|
  Case RTB_JAVASCRIPT
   buttonCode = |<javascript>| & XmlConvert(code) & |</javascript>| 
   codeStr = "<code for='web' event='onClick'>"
   '** JavaScript按钮的<code>代码
  End Select
  
  buttonTag = |<button width='2in' widthtype='fitcontent' wraptext='true' |
  If (edgeType = RTB_SQUARE) Then
   buttonTag = buttonTag & | edge='square' |
  Else
   buttonTag = buttonTag & | edge='rounded' |
  End If
  buttonTag = buttonTag & | bgcolor='system'>|
  
  '** DXL that will create a temporary doc with the button we want.
  '** We're adding the current user name in an Author field on
  '** this temporary document because we'll be deleting it at the end
  '** of this function, and the user may only have Author access to
  '** this database.
  dxl = |<?xml version='1.0' encoding='ISO-8859-1'?>
  <!DOCTYPE document SYSTEM 'xmlschemas/domino_6_5.dtd'>
<document xmlns='http://www.lotus.com/dxl' version='6.5'
 replicaid='0123456789ABCDEF' form='ButtonMaker'>
<item name='DocAuthor' authors='true' names='true'>
<text>| & XmlConvert(session.CommonUserName) & |</text></item>
  <item name='Body'><richtext>
<pardef id='1'/>
<par def='1'>
| & buttonTag  & codeStr &  buttonCode & |</code>| & XmlConvert(label) & |</button></par></richtext>
  </item>
</document>|
  Msgbox dxl
  '** create a new doc using the DXL above
  Set db = session.CurrentDatabase
  Set importer = session.CreateDXLImporter(dxl, db)
  importer.ReplicaRequiredForReplaceOrUpdate = False
  importer.DocumentImportOption = DXLIMPORTOPTION_CREATE
  Call importer.Process
  
  '** get the button from the doc we just created and append it to
  '** the rich text item we were given
  Set doc = db.GetDocumentByID(importer.GetFirstImportedNoteId)
  Set body = doc.GetFirstItem("Body")
  Call rtitem.AppendRTItem(body)
  
  '** try to delete the temporary doc. In case we can't delete it for some
  '** reason, a scheduled agent should be written to globally delete
  '** docs that use the form name specified in the DXL above.
  On Error Resume Next
  Call doc.RemovePermanently(True)
  
  Exit Function
  
  
processError:
  If (importer.Log <> "") Then
   AppendButton = importer.Log
  Else
   AppendButton = "Error " & Err & " on line " & Erl & ": " & Error$
  End If
  Exit Function
 End Function
 
 
End Class
Sub Initialize
 
 '** here's an example of how to call the class
 Dim session As New NotesSession
 Dim doc As NotesDocument
 Dim rtitem As NotesRichTextItem
 Dim button1 As New RichTextButton
 Dim button2 As New RichTextButton
 Dim result As String
 
 '** grab the first selected doc in the view
' Set doc = session.CurrentDatabase.UnprocessedDocuments.GetFirstDocument
 Set doc = session.DocumentContext
 Set rtitem = doc.GetFirstItem("Body")
 If (rtitem Is Nothing) Then
  Set rtitem = New NotesRichTextItem(doc, "Body")
 End If
 
 '** append a JavaScript button to the body
 Call button1.SetLabel("JavaScript Button & Stuff")
 Call button1.SetButtonLanguage(RTB_JAVASCRIPT)
 Call button1.SetCode( |
alert("测试");
| )
 Call rtitem.AddNewline(1)
 result = button1.AppendButton(rtitem)
 If (result <> "") Then
  Call rtitem.AppendText("There was an error creating the button. " & result)
 End If
 
 '** append a Formula button to the body
 Call button2.SetLabel("Formula Button")
 Call button2.SetEdgeType(RTB_SQUARE)
 Call button2.SetButtonLanguage(RTB_FORMULA)
 Call button2.SetCode( |@Prompt([ok]; "My Button"; "You clicked my button");| )
 Call rtitem.AddNewline(1)
 result = button2.AppendButton(rtitem)
 If (result <> "") Then
  Call rtitem.AppendText("There was an error creating the button. " & result)
 End If
 
 '** save and exit
 Call doc.Save(True, True)

DXL应用:向设计元素中添加设计元素相关推荐

  1. navicat设计表中添加自增长列

    写web通讯录的时候在添加联系人时候需要主键故采用自增长列为主键,百度链接有详细教程 点击打开链接,注意的是在设计表中添加栏位后把类型改成bigint才会出现自增长选项,希望对你有用

  2. 圣诞节PNG免扣素材|轻松向现有项目中添加节日元素!

    制作任何东西,从定制的圣诞卡,图标,可以用于网站设计或包装,甚至图形,照片和插图,PNG免扣格式图片素材,无疑可以帮助你有效的完成项目. 节日的装饰不仅仅包括挂一棵圣诞树和添加金属箔.装饰也可以延伸到 ...

  3. Html怎样往div中添加文本,给div中添加文本元素

    [javascript]代码库 给div中添加文本元素 div{ border: 1px solid blue; background-color: green; width: 300px; heig ...

  4. 清除元素中的子元素html_HTML中的元素简介

    清除元素中的子元素html An element is a fundamental component that is used to develop web pages. Generally an ...

  5. kotlin List删除一个元素,添加一个元素

    kotlin List移除一个元素,添加一个元素时没有 remove和add函数只有 -= 和 += 在kotlin ArrayList中才有remove和add函数 没有 -= 和 += kotli ...

  6. 从键盘输入一个4x4整数矩阵,以主对角线为对称轴,将右上角元素中较大元素代替左下角对应元素,并将左下角元素

    从键盘输入一个4x4整数矩阵,以主对角线为对称轴,将右上角元素中较大元素代替左下角对应元素,并将左下角元素(含对角线元素)输出.注意处理输入输出显示 #include <stdio.h> ...

  7. 删除列表元素中最后一个元素

    删除列表元素中最后一个元素 清楚明了 壹 <title></title><script src="js/jquery.js"></scri ...

  8. KiCad设计PCB-40-PCB中添加开窗的logo、丝印层添加英文和中文注释

    PCB中添加开窗的logo 开窗的意思是去掉电路板中走线等上面的绿油,把铜皮裸露出来.本篇就是给大家介绍如何在开发板上通过开窗的手法做自己的logo.由于KiCad软件不支持中文,因此写中文要借助于K ...

  9. matlab能做什么设计,MATLAB中GUI设计领悟

    最近在给宝钢做一个基于MATLAB平台的操作界面,用到了有关GUI的东西.为此特地学习了一下有关知识,在论坛里逛来逛去,也没有发现非常有价值的东西,反而让自己更加的郁闷和烦乱,后来又狠下心来耐心的看了 ...

  10. 怎么将多个html组合_技巧分享之在HTML元素中添加逼真阴影的教程

    添加一个简单的阴影 让我们为投影准备一个简单的HTML元素: 然后添加CSS: 输出结果是三个框,通过调用每个框的ID可以很容易地放置阴影.要添加阴影,让我们将属性box-shadow赋予框1: 我们 ...

最新文章

  1. c 读取html text,Converting HTML text into plain text using Objective-C
  2. 波士顿动力最新仓储机器人,每小时“搬砖”800块
  3. xshell使用xftp传输文件 使用pure-ftpd搭建ftp服务
  4. mysql创建用户以及授权
  5. spring4.x(13)---SpringEL-操作List、Map
  6. Smith Numbers POJ - 1142 (暴力+分治)
  7. OS X Capitan 和 macOS Sierra U盘安装
  8. mysql my.ini设置root密码_mysql 5.7设置root密码 windows
  9. Linux -- Reactor
  10. linux聪某个附属组删除_linux-user-group添加与删除
  11. NAT with same subnetwork
  12. Oracle表名、列名、约束名的长度限制
  13. Spark大数据计算引擎介绍
  14. 为什么计算机无法访问u盘,打开U盘后为什么提示拒绝访问 打开U盘后提示拒绝访问原因...
  15. QQ群创建者和管理员
  16. 秀场直播的四种实现方式,让我们从方案架构进行分析
  17. NOJ——1665夜神的思考(YY+组合问题+分类讨论)
  18. Faceless geometries are not supported
  19. oracle的LAST_DAY()函数
  20. Android5.0录屏

热门文章

  1. 动态滑窗-python
  2. SQL在线格式化工具
  3. python代码求和_python求和代码
  4. [Go实战]goFrame框架初次使用
  5. 吴恩达机器学习作业2
  6. C#TTS语音播报带背景音乐
  7. Unicode官网Code Charts下载。
  8. gns3中怎么把服务器虚拟化,GNS3使用详解(gns3如何模拟ids)
  9. python调用按键精灵插件_按键精灵教程打码平台接入
  10. 四川大学软件学院操作系统笔记