1

我正在尝试将我的访问数据库中的项目导出到 lotus notes。我要导出到的文档是固定的,并且所有数据都写入其中,我只需要以某种方式标记占位符,然后更新值。我已经阅读了文档,看来我需要处理字段,然后调用一个方法来替换文本,如下所示:

'where body is the field and the following string is what to replace field with
Call doc.ReplaceItemValue("body", "REPLACE BODY")

需要明确的是,我的整个代码如下所示:

Set session = CreateObject("Notes.NotesSession")
Set maildb = session.GetDatabase("server", "mail\box.nsf")

Set View = maildb.GetView("Stationery")
Set entries = View.AllEntries

Set entry = entries.GetFirstEntry

Set doc = entry.Document

Call doc.ReplaceItemValue("Subject", "Report - " & Date)
'add code here
Call doc.send(False, "person.to.receive@thisemail.com")


End Sub

我注意到,在阅读文档时,似乎可以创建字段,然后处理这些字段以更新值。例如,如果我有一个名为 $COST 的字段,那么可以这样做:

Call doc.ReplaceItemValue("$COST", "The cost is $3000")

并且应该更新该字段以反映我通过该方法传递的值。我的大问题是,即使查看文档,我也无法弄清楚我需要去哪里添加自定义字段。文档似乎假设您知道如何创建这些字段并解决它们。还是我只应该以编程方式创建这些字段然后填写数据?我的客户是 Lotus Notes 8。谢谢!

4

2 回答 2

1

是的,这就是 IBM Lotus Notes 数据库的酷炫之处:您可以将项目(=字段)放入 Notes 文档中,而无需事先定义字段。

如果您在文档中创建项目doc.ReplaceItemValue()并保存或发送文档,那么项目就在那里。您可以在打开所选文档的属性框时检查项目。所有项目都列在文档属性的第二个选项卡上。

另一个问题当然是在表单中定义字段,以便用户可以看到创建的项目,而无需查看文档属性框。在 Designer 中打开数据库并将字段放置在正确的位置和大小以形成。

您的问题和评论告诉您要创建一个文档,用数据填充它并将其发送给用户。

如果所有用户都可以访问您的 Notes 服务器,那么您可以在现有数据库中创建该文档并仅向用户发送链接邮件。通过这种方式,您可以创建一个漂亮的表单并定位所有数据字段。用户将通过链接访问数据库中的文档。

另一种方法是创建一个漂亮的 HTML 文件,将其附加到邮件中并发送。在这种情况下,您可以将此代码添加到您的示例中'add code here

Call doc.RemoveItem("Body")
Set rtitem = doc.CreateRichTextItem( "Body" )
Call rtitem.AppendText("your mail text")
Call rtitem.EmbedObject(EMBED_ATTACHMENT, "", "report.html")
于 2013-09-03T19:50:19.483 回答
0

Based on the comment thread on @Knut Herrmann's answer, I believe that the solution you really want involves using "stored form". The first argument to the NotesDocument.Send() method is a boolean that specifies whether you want to store the form or not.

Normally, you would use Domino Designer to create a stored form. You would not need Designer rights to anyone's mailbox. You would just need to create an empty database of your own, and put a form into it. You woould change your code to open that database and create the document in there instead of in a mailbox database as you are doing now. (One of the other cool things about Notes is that you don't actually have to be working in a mailbox database in order to mail a document. You can mail any document from any database, as long as you put the approporiate fields into it.)

There is also a way to do this without Domino Designer, and you could even dynamically generate the form with truly custom fields that your code only discovers as it runs. You could do this with DXL, which is an XML format for describing Lotus Notes objects, including forms. You would just need some sample DXL to work from. Preferably that should be of an empty database that contains a simple form that is set up more or less in the layout that you would want, though again you would need Domino Designer for that. You could just use the same mailbox database that your code is currently using, but that will leave you with a lot of extra stuff in the DXL that doesn't need to be there; and given that you're not all that familiar with Notes, it would likely be difficult for you to navigate through it all to find what you need.

Either way, though, you could use the NotesDXLExporter class to generate the DXL file. Your code could manipulate the DXL, adding/changing elements as needed (following the pattern that you see in sample, of course), and they you could use NotesDXLImporter to create the database that your code will actually use to create the document in and mail the message with the stored form.

于 2013-09-04T00:27:16.050 回答