编辑注:您很精通这个主题吗?希望分享您的经验吗?请马上加入到 IBM Lotus 软件 wiki 项目。
| IBM Lotus Notes and Domino wiki | Lotus Symphony wiki |
|---|
大多数 Lotus Notes 开发人员都熟悉 Lotus Notes 中的发布限制。开发人员经常需要创建带有 Lotus Notes 应用程序中的数据的邮件,创建带有特定格式的报告,或者支持其他功能,比如 DataPilot 表。Lotus Notes 本身并不支持这些特性。
从 Lotus Notes 8 开始,IBM Lotus Symphony 生产力套件作为一个可选的免费应用程序包含进来,它可以安装在 Lotus Notes 客户端上。该套件包含以下应用程序:
- Lotus Symphony Documents,一个字处理程序
- Lotus Symphony Spreadsheets,一个电子表格程序
- Lotus Symphony Presentations,一个演示程序
作为一名 Lotus Notes 开发人员,您可以开发利用 Lotus Symphony Toolkit for Lotus Notes 的发布解决方案。这个工具包提供创建发布 Lotus Notes 数据库中的存储信息的解决方案的功能。这个工具包受到 Lotus Notes 8.5.1 或更高版本的支持。本文主要关注如何使用 Lotus Symphony Documents 和 Lotus Symphony Spreadsheets 发布信息。
本文包含一些代码段示例并提供一个可以下载的示例数据库。示例 Lotus Notes 应用程序包含以下代理:
- 创建一个 Lotus Symphony 文档。这个由样例代码构成的代理将生成一个 Lotus Symphony 文档。这个代理还包含以一种隐藏方式创建和处理文档的帮助提示。
- 创建一个 Lotus Symphony 电子表格。这个由样例代码构成的代理将生成一个 Lotus Symphony 电子表格。
- 样例文档报告。这个代理提供一个处理 Lotus Symphony 文档的详细示例,基于 Lotus Notes 数据创建一个报告。
- 样例电子表格报告。这个代理提供一个处理 Lotus Symphony 电子表格的更详细的示例,基于 Lotus Notes 数据创建一个 DataPilot 表。
要使用本文提供的代码,您必须启用 Lotus Symphony 嵌入特性,原因是样例被编写为运行在本地系统上的由用户触发的代理。
另外,这个工具包只在 Microsoft® Windows® 和 Linux® 受到支持。
最后,Lotus Symphony 支持以下文件格式:
- Open Document Format (ODF) 1.1 读/写
- Microsoft 97-2003 读/写
- Microsoft 2007 DOCX 读
- Lotus SmartSuite® 读
- Comma-separated value (CSV) / Tab-separated value (TSV) 读
本文假定您熟悉 LotusScript 和对象模型的概念。
本小节主要介绍创建 Lotus Symphony 应用程序及其关联对象的句柄的基础知识。样例代码仅供参考,完整的样例可以从样例应用程序中获取。
在 Lotus Notes 和其他应用程序之间共享数据的第一步是获取对目标应用程序的引用。尽管在简单的应用程序中创建引用并不是必须的,包含一个对 Lotus Symphony LSS 文件的引用允许您使用与一些常见行为(如设置字体格式、声明图表类型和设置文件格式等)关联的常量。
(Options)
%INCLUDE "symphonylsx.lss"
您需要使用对象变量来表示 Lotus Symphony 应用程序和对象类型,方法是创建一个指向 Lotus Symphony 应用程序的引用:
'The following line creates a handle to the
‘Symphony application object.
Dim symphony As New SymphonyApplication
至此,您可以开始通过 LotusScript 控制那个应用程序,执行打开文档、传递文本、格式化文本等常见任务。参见清单 1。
清单 1. 创建一个对文档的引用和一个新文档
‘These next lines will represent the ‘Documents collection and a Document object Dim symDocuments As SymphonyDocuments Dim symDocument As SymphonyDocument |
下面是您可能想要利用的 3 个 Lotus Symphony 应用程序对象类:
- SymphonyApplication.Documents
- SymphonyApplication.Spreadsheets
- SymphonyApplication.Presentations
从前面的代码段继续,您可以使用 LotusScript 传递文本到 Lotus Symphony 文档。但首先,您需要获取一个对新文档的引用,如清单 2 所示。
清单 2. 获取一个对新文档的引用
‘The following lines create a handle to the ‘Symphony documents collection, and create a ‘new document Set symDocuments = symphony.Documents Set symDocument = symDocuments.AddDocument() |
在第 2 行中,您将 Lotus Symphony 对象模型从应用程序对象导航到该应用程序的文档集合。从那里,您使用 Add 方法,这将创建一个文档并返回一个对该文档的引用。
要查看 Lotus Symphony 文档或应用程序的对象模型,您可以打开一个文档并从菜单选择 Tools - Macros - Macro。图 1 显示打开的窗口。
图 1. Macro 窗口
单击 Edit 按钮,显示如图 2 所示的 BASIC Editor 窗口。
图 2. Lotus Symphony BASIC Editor 窗口
下面,单击 Object Catalog 按钮,如图 3 所示。
图 3. Object Catalog 按钮
Object Organizer 窗口将显示出来,如图 4 所示。
图 4. Objects 窗口
这个窗口以层级方式显示所有现有对象的列表。双击一个列表条目将打开它的从属对象。
另一个选项是使用 Lotus Domino Classes 引用选项卡,如图 5 所示。在 IBM Lotus Domino Designer 中编辑 LotusScript 代理时,这个选项卡是可以访问的。
图 5. Lotus Domino Designer 中的 Reference 选项卡显示 Lotus Symphony 类
SymphonyDocument 对象包含许多需要检查的方法。但是,在向文档中输入文本前,需要考虑光标的位置。即使以编程方式在文档上执行操作,Lotus Symphony 的行为亦会像与用户手动交互一样。
例如,当您在 Lotus Notes 中创建一个 Lotus Symphony 文档时,光标显示在页面的顶部。当您以编程方式创建一个文档时,光标仍然显示在页面的顶部。因此,让我们看看 Selection.Range 对象的用法:
Dim txtRange As SymphonyTextRange
Set txtRange = symDocument.Selection.Range
这两行代码提供一个对 SymphonyTextRange 对象的引用。下面,您可以使用 Text 属性向文档中输入文本。
Selection 对象包含 Text 属性,该属性用于将一个字符字符串传递到当前文档:
txtRange.Text = "Hello, world!"
这段代码将常见的 “Hello, world!” 文本字符串传递到活动文档中光标当前所在的位置。
当您想要格式化 Lotus Symphony 文档中的文本时,您选择该文本并应用您的格式化更改。例如,您也许想对刚才输入的 “Hello, world!” 字符串应用粗体字体:
txtRange.Font.Bold = True
这段代码将粗体格式应用到当前选中的范围。
可以使用类似于清单 3 的代码创建一个 Lotus Symphony 电子表格。
清单 3. 创建一个 Lotus Symphony 电子表格
(Options) %Include "symphonylsx.lss" Dim symphony As New SymphonyApplication Dim symSheeets As SymphonySpreadsheets Dim symSheet As SymphonySpreadsheet Set symSheets = symphony.Spreadsheets() Set symSheet = symDocuments.AddSpreadsheet() |
总之,您遵循的流程从对象模型的最高级别(SymphonyApplication 对象)逐步向下深入。通过使用各种变量,您获得对经常使用的不同对象的引用。检查清单 4 中的完整代码。您可以复制并粘贴这段代码到一个代理中并使用 LotusScript 调试器逐步调试它,看看它是如何工作的。
清单 4. 完整的代码
Dim symphony As New SymphonyApplication Dim symDocuments As SymphonyDocuments Dim symDocument As SymphonyDocument Set symDocuments = symphony.Documents Set symDocument = symDocuments.AddDocument() Dim txtRange As SymphonyTextRange Set txtRange = symDocument.Selection.Range txtRange.Text = "This is my first Symphony document!" txtRange.Font.Bold = True Set txtRange = symDocument.Paragraphs.Item(2).Range txtRange.Font.Bold = False txtRange.Text = "This is great!" |
使用 Lotus Symphony Documents 创建一个报告
考虑一下这个场景:您是一位程序管理员,使用一个 Lotus Notes 应用程序跟踪您的程序中的项目。您经常需要检查关于一个或多个项目和它们的相关成本的信息。
您已经熟悉如何使用工具包提供的 Lotus Notes 对象和 Lotus Symphony 对象。您可以使用类似于清单 5 的代码创建一个代理,这将创建理想的报告。样例数据库包含一个名为 All Projects 的视图和一个名为 Sample Document Report 的样例代理。
清单 5. 在一个 Lotus Symphony 文档中创建一个报告的样例代码
%REM
Agent 3) Sample Document Report
Created Jul 23, 2009 by Symphony Developer/Symphony Developer
Description: Comments for Agent
%END REM
Option Public
Option Declare
%Include "symphonylsx.lss"
Sub Initialize()
'Declare the Notes object variables
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim v As NotesView
Dim vnav As NotesViewNavigator
Dim entry As NotesViewEntry
Dim doc As NotesDocument
Dim colCosts As NotesDocumentCollection
Dim cost As NotesDocument
Dim mgr As String
Dim planned As Currency
Dim actual As Currency
Dim variance As Currency
Dim cuser As NotesName
Set db = sess.Currentdatabase
Set v = db.GetView("All Projects")
Set vnav = v.Createviewnav()
Set entry = vnav.Getfirstdocument()
If entry Is Nothing Then
MsgBox "No documents found", , "Exiting"
Exit sub
End If
'Declare the Symphony object variables
Dim symphony As New SymphonyApplication
Dim rptDoc As SymphonyDocument
%REM
Generally, I would create the document in "invisible" mode. To
see this is action, uncomment the following line and comment the
line after the next REM block.
%END REM
'Set rptDoc = symphony.Documents.AddDocument("", False, False)
%REM
I typically use the following line during development/debugging,
then switch to the line above for production.
%END REM
Set rptDoc = symphony.Documents.AddDocument()
Dim txtRange As SymphonyTextRange
Set txtRange = rptDoc.Selection.Range
txtRange.Text = "Project Summary Report"
txtRange.Horialignment = SYMPHONY_TEXT_HORI_ALIGN_CENTER
txtRange.Font.Bold = True
txtRange.Font.Height = 16
Call txtRange.InsertBreak(txtRange.End, SYMPHONY_TEXT_BREAK_PARAGRAPH)
Set txtRange = rptDoc.Paragraphs.Item(2).Range
txtRange.Text = "prepared " & CStr(Today)
Call txtRange.InsertBreak(txtRange.End, SYMPHONY_TEXT_BREAK_APPEND_PARAGRAPH)
Set txtRange = rptDoc.Paragraphs.Item(3).Range
Set cuser = New NotesName(sess.Commonusername)
txtRange.Text = "by " & cuser.Common
Call txtRange.InsertBreak(txtRange.End, SYMPHONY_TEXT_BREAK_APPEND_PARAGRAPH)
Call txtRange.InsertBreak(txtRange.End, SYMPHONY_TEXT_BREAK_APPEND_PARAGRAPH)
Set txtRange = rptDoc.Paragraphs.Item(5).Range
txtRange.Horialignment = SYMPHONY_TEXT_HORI_ALIGN_LEFT
txtRange.Font.Bold = False
txtRange.Font.Height = 12
'Begin walking the documents in the view, and passing the
'values into the Symphony document.
Do Until entry Is Nothing
Set doc = entry.Document
Set txtRange = rptDoc.Paragraphs.Item(rptDoc.Paragraphs.Count).Range.End
Select Case doc.Form(0)
Case "ProjectSummary"
'Print desired information for Project documents
If (mgr = "") Or (mgr <> doc.PrjMgr(0)) Then
mgr = doc.PrjMgr(0)
Call txtRange.InsertBreak(txtRange.End, _
SYMPHONY_TEXT_BREAK_APPEND_PARAGRAPH)
Set txtRange = rptDoc.Paragraphs.Item(rptDoc.Paragraphs.Count).Range.End
txtRange.Text = "Projects managed by " & mgr
Call txtRange.InsertBreak(txtRange.End, _
SYMPHONY_TEXT_BREAK_APPEND_PARAGRAPH)
txtRange.Font.Bold = True
End If
Call txtRange.InsertBreak(txtRange.End, _
SYMPHONY_TEXT_BREAK_APPEND_PARAGRAPH)
Set txtRange = rptDoc.Paragraphs.Item(rptDoc.Paragraphs.Count).Range.End
txtRange.Text = doc.PrjName(0) & " - " & doc.PrjStatus(0)
Call txtRange.InsertBreak(txtRange.End, _
SYMPHONY_TEXT_BREAK_APPEND_PARAGRAPH)
txtRange.Font.Italic = True
Case "Task"
'Print desired information for Task documents
Set txtRange = rptDoc.Paragraphs.Item(rptDoc.Paragraphs.Count).Range.End
txtRange.Text = "- " & doc.TaskDesc(0)
Call txtRange.InsertBreak(txtRange.End, _
SYMPHONY_TEXT_BREAK_APPEND_PARAGRAPH)
'Calculate and print desired information for Cost documents
planned = 0
actual = 0
variance = 0
Set colCosts = doc.Responses()
If colCosts.Count > 0 Then
Set cost = colCosts.Getfirstdocument()
Do Until cost Is Nothing
If IsNumeric(cost.CapPln(0)) Then
planned = planned + cost.CapPln(0)
End If
If IsNumeric(cost.ExpPln(0)) Then
planned = planned + cost.ExpPln(0)
End If
If IsNumeric(cost.CapAct(0)) Then
actual = actual + cost.CapAct(0)
End If
If IsNumeric(cost.ExpAct(0)) Then
actual = actual + cost.ExpAct(0)
End If
Set cost = colCosts.Getnextdocument(cost)
Loop
variance = planned - actual
End If
Set txtRange = rptDoc.Paragraphs.Item(rptDoc.Paragraphs.Count).Range.End
txtRange.Text = " Planned: " & Format$(planned, "$#,##0") & _
" Actual: " & Format$(actual, "$#,##0") & _
" Variance: " & Format$(variance, "$#,##0")
Call txtRange.InsertBreak(txtRange.End, _
SYMPHONY_TEXT_BREAK_APPEND_PARAGRAPH)
End Select
Set entry = vnav.Getnextdocument(entry)
Loop
'Clean up
Print "Cleaning up..."
Set txtRange = Nothing
Set rptDoc = Nothing
Set symphony = Nothing
Set cost = Nothing
Set colCosts = Nothing
Set doc = Nothing
Set entry = Nothing
Set vnav = Nothing
Set v = Nothing
Set db = Nothing
Set sess = Nothing
MsgBox "Complete", , "You report is now complete."
End Sub
|
使用 Lotus Symphony Spreadsheets 创建一个报告
考虑一下这个场景:您是一个小公司的销售总监,您想使用各种透视图查看最近的销售情况。一个 Lotus Notes 数据库包含上月的订单。
和前一个示例一样,您可以使用 NotesViewNavigator 访问 Lotus Notes 中所需的数据,然后在 Lotus Symphony 电子表格中输入数据。这个示例的独特性在于您还使用一个 DataPilot 表来显示和分析数据。
DataPilot 特性是快速合并、比较和分析大量数据的强大工具。这些数据可以根据不同的角度进行整理、重新整理或求和。要了解关于 DataPilot 表的更多信息,请参阅 IBM Lotus Symphony Information Center:
http://publib.boulder.ibm.com/infocenter/symphony/v1r1/index.jsp?topic=/com.ibm.help.symphony13.doc/welcome.html
样例数据库包含一个名为 Orders 的视图和一个名为 Sample Spreadsheet Report 的样例代理。
清单 6 显示在 Lotus Symphony 电子表格中创建一个报告的代码。
清单 6. 在 Lotus Symphony 电子表格中创建一个报告的样例代码
%REM
Agent 4) Sample Spreadsheet Report
Created Jul 23, 2009 by Symphony Developer/Symphony Developer
Description: Comments for Agent
%END REM
Option Public
Option Declare
%Include "symphonylsx.lss"
Sub Initialize()
'Declare the Notes object variables
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim v As NotesView
Dim vnav As NotesViewNavigator
Dim entry As NotesViewEntry
Dim row As long
'These lines obtain a handle to the 'Orders' view,
'and the first entry in it.
Set db = sess.Currentdatabase
Set v = db.GetView("Orders")
Set vnav = v.Createviewnav()
Set entry = vnav.Getfirstdocument()
If entry Is Nothing Then
MsgBox "No documents found", , "Exiting"
Exit Sub
End If
'Declare the Symphony object variables
Dim symphony As New SymphonyApplication
Dim rptSht As SymphonySpreadsheet
Dim dataSheet As Symphonysheet
Dim dpSheet As Symphonysheet
'Variables below are for the DataPilot
Dim dataPilotTables As SymphonyDataPilotTables
Dim dataPilotTable As SymphonyDataPilotTable
Dim src As SymphonyRange
Dim dst As SymphonyRange
%REM
Generally, I would create the document in "invisible" mode. To
see this is action, uncomment the following line and comment the
line after the next REM block.
%END REM
'Set rptSht = symphony.Spreadsheets.AddSpreadsheet("", False, False)
%REM
I typically use the following line during development/debugging,
then switch to the line above for production.
%END REM
Set rptSht = symphony.Spreadsheets.Addspreadsheet("")
%REM
The next few lines of code create and name 2 sheets. The first sheet
is called 'Data' and will contain the actual data used as the source for
the second sheet.
The second sheet will be used to display and manipulate the DataPilot.
%END REM
Set dataSheet = rptSht.Activesheet
dataSheet.Name = "Data"
Call rptSht.Sheets.Addto(dataSheet, 1, False)
Set dpSheet = rptSht.Sheets.Item(2)
dpSheet.Name = "DataPilot"
'The following lines create the header row in the source table.
With dataSheet
.Cells(1, 1).Text = "Rep"
.Cells(1, 2).Text = "Customer"
.Cells(1, 3).Text = "Region"
.Cells(1, 4).Text = "Product"
.Cells(1, 5).Text = "Num Units"
.Cells(1, 6).Text = "Price"
.Cells(1, 7).Text = "Total"
.Range("A1:G1").Font.Bold = True
End With
' The next lines pass the data from Notes into the spreadsheet.
row = 1
Do Until entry Is Nothing
row = row + 1
dataSheet.Cells(row, 1).Text = entry.Columnvalues(0)
dataSheet.Cells(row, 2).Text = entry.Columnvalues(1)
dataSheet.Cells(row, 3).Text = entry.Columnvalues(2)
dataSheet.Cells(row, 4).Text = entry.Columnvalues(3)
dataSheet.Cells(row, 5).Value = entry.Columnvalues(4)
dataSheet.Cells(row, 6).Value = entry.Columnvalues(5)
dataSheet.Cells(row, 7).Value = entry.Columnvalues(6)
Set entry = vnav.Getnextdocument(entry)
Loop
'Finally, these lines create the DataPilot.
Set dataPilotTables = dpSheet.DataPilotTables
Set src = dataSheet.Range("A1:G" & CStr(row))
Set dst = dpSheet.Cells(1, 1)
Set dataPilotTable = dataPilotTables.Add(src,"DPT_ORDERS",dst)
Dim rowFieldsString(0) As String
rowFieldsString(0) = "Rep"
Dim colFieldsString(0) As String
colFieldsString(0) = "Region"
Dim dataFieldsString(0) As String
dataFieldsString(0) = "Total"
Dim pageFieldsString(0) As String
pageFieldsString(0) = "Product"
Call dataPilotTable.AddFields(rowFieldsString, colFieldsString, _
dataFieldsString, pageFieldsString, SYMPHONY_GENERAL_FUNCTION_SUM)
End Sub
|
IBM Lotus Symphony 工具包是一个强大的工具,经验丰富的 LotusScript 开发人员能够利用它快速开发范围广泛的发布解决方案。您从本文了解到,可以以多种格式发布来自 Lotus Notes 数据库的内容。您可以在 Lotus Symphony 文档中生成报告,还可以使用 Lotus Symphony 电子表格执行分析甚至创建图表。
感谢 Paul Bastide、Jin Hua Chen、Da Li Yin 和 Linda Li 的技术审校。
| 名字 | 大小 | 下载方法 |
|---|---|---|
| SymphInt.nsf | 448KB | HTTP |
- 参与论坛讨论。
-
参见 IBM Lotus Symphony Information Center,这个站点会定期更新以反映产品更新。
-
参见 IBM Lotus Symphony page of IBM Lotus developerWorks®,它包含丰富的信息和许多有帮助的链接,其中包括到 Lotus Symphony Developers Toolkit 的链接。
-
在 Lotus Symphony Wiki 阅读最新信息并为其撰写条目。
-
了解关于 OpenOffice.org 的更多信息。