如何使用 LotusScript 将富文本字段从 Notes 导出为 HTML?

发布于 2024-08-13 17:24:37 字数 1084 浏览 10 评论 0原文

我正在执行一项数据迁移任务,必须将一个较大的 Lotus Notes 应用程序导出到博客平台中。我的第一个任务是将 Lotus Notes 中的文章导出到 CSV 文件中。

我在 LotusScript 中创建了一个代理来将数据导出到 CSV 文件中。我使用此 IBM DeveloperWorks 论坛帖子的修改版本。它基本上完成了这项工作。但富文本字段的内容已去除任何格式。这不是我想要的,我希望富文本字段呈现为 HTML。

GetItemValue 方法的文档明确指出文本是呈现为纯文本。所以我开始研究可以检索 HTML 的东西。我在 IBM 文章 How To Access 中找到了 NotesMIMEEntity 类和一些示例代码使用 LotusScript 的富文本字段中的 HTML

但要使上述文章中描述的技术发挥作用,富文本字段需要具有“将内容存储为 HTML 和 MIME”属性。我的 Lotus Notes 数据库并非如此。我尝试在相关字段上设置属性,但没有成功。

是否可以使用 NotesMIMEEntity 并在添加内容后设置“将内容存储为 HTML 和 MIME”属性,以导出呈现为 HTML 的字段?

或者,将 Notes 数据库富文本字段导出为 HTML 的选项有哪些?

额外信息:我正在使用 IBM Lotus Domino Designer 版本 8.5

I'm working on a data migration task, where I have to export a somewhat large Lotus Notes application into a blogging platform. My first task was to export the articles from Lotus Notes into CSV files.

I created a Agent in LotusScript to export the data into CSV files. I use a modified version of this IBM DeveloperWorks forum post. And it basically does the job. But the contents of the Rich Text field is stripped of any formatting. And this is not what I want, I want the Rich Text field rendered as HTML.

The documentation for the GetItemValue method explicitly states that the text is rendered into plain text. So I began to research for something that would retrieve the HTML. I found the NotesMIMEEntity class and some sample code in the IBM article How To Access HTML in a Rich Text Field Using LotusScript.

But for the technique described in the above article to work, the Rich Text field need to have the property "Store Contents as HTML and MIME". And this is not the case with my Lotus Notes database. I tried to set the property on the fields in question, but it didn't do the trick.

Is it possible to use the NotesMIMEEntity and set the "Store Contents as HTML and MIME" property after the content has been added, to export the field rendered as HTML?

Or what are my options for exporting the Notes database Rich Text fields as HTML?

Bonus information: I'm using IBM Lotus Domino Designer version 8.5

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

栖迟 2024-08-20 17:24:37

有一个相当未知的命令可以完全满足您的要求:使用命令 OpenField 检索 URL。

仅转换 Body 字段的示例:

http://SERVER/your%5Fdatabase%5Fpath.nsf/NEW%5FVIEW/docid/Body?OpenField

There is this fairly unknown command that does exactly what you want: retrieve the URL using the command OpenField.

Example that converts only the Body-field:

http://SERVER/your%5Fdatabase%5Fpath.nsf/NEW%5FVIEW/docid/Body?OpenField
毁梦 2024-08-20 17:24:37

这是我使用 OpenField 命令的方法,请参阅上面 D.Bugger 的帖子

Function GetHtmlFromField(doc As NotesDocument, fieldname As String) As String
    Dim obj
    Set obj = CreateObject("Microsoft.XMLHTTP")
    obj.open "GET", "http://www.mydomain.dk/database.nsf/0/" + doc.Universalid + "/" + fieldname + "?openfield&charset=utf-8", False, "", ""
    obj.send("")

    Dim html As String
    html = Trim$(obj.responseText)

    GetHtmlFromField = html
End Function

Here is how I did it, using the OpenField command, see D.Bugger's post above

Function GetHtmlFromField(doc As NotesDocument, fieldname As String) As String
    Dim obj
    Set obj = CreateObject("Microsoft.XMLHTTP")
    obj.open "GET", "http://www.mydomain.dk/database.nsf/0/" + doc.Universalid + "/" + fieldname + "?openfield&charset=utf-8", False, "", ""
    obj.send("")

    Dim html As String
    html = Trim$(obj.responseText)

    GetHtmlFromField = html
End Function
水中月 2024-08-20 17:24:37

我建议查看 Midas 的 Rich Text LSX (http://www.geniisoft.com/showcase .nsf/MidasLSX

我个人没有使用过,但我记得几年前它们是处理富文本的最佳选择。我敢打赌它可以帮你省去很多麻烦。

至于 NotesMIMEEntity 类,我不认为有办法将 RichText 转换为 MIME,只能将 MIME 转换为 RichText(或在文档中保留 MIME 以用于电子邮件发送)。

I'd suggest looking at Midas' Rich Text LSX (http://www.geniisoft.com/showcase.nsf/MidasLSX)

I haven't used the personally, but I remember them from years ago being the best option for working with Rich Text. I'd bet it saves you a lot of headaches.

As for the NotesMIMEEntity class, I don't believe there is a way to convert RichText to MIME, only MIME to RichText (or retain the MIME within the document for emailing purposes).

迷乱花海 2024-08-20 17:24:37

如果升级到 Notes Domino 8.5.1,则可以使用 NotesDocument 类的新 ConvertToMIME 方法。请参阅文档。这应该做你想做的。

另外,让 Domino 服务器呈现 RichText 的最简单方法是通过 url 调用实际检索它。设置一个仅包含 RichText 字段的简单表单,然后使用您最喜欢的 HTTP api 拉入页面。然后应该可以非常直接地拉出主体。

If you upgrade to Notes Domino 8.5.1 then you can use the new ConvertToMIME method of the NotesDocument class. See the docs. This should do what you want.

Alternativly the easiest way to get the Domino server to render the RichText will be to actually retrieve it via a url call. Set up a simple form that just has the RichText field and then use your favourite HTTP api to pull in the page. It should then be pretty straight forward to pull out the body.

池木 2024-08-20 17:24:37

保持简单。

将 BODY 字段更改为将内容存储为 HTML 和 MIME

在编辑模式下打开文档。
节省。
关闭。

您现在可以使用 NotesMIMEEntity 从脚本中获取所需内容。

Keep it simple.

Change the BODY field to Store contents as HTML and MIME

Open the doc in editmode.
Save.
Close.

You can now use the NotesMIMEEntity to get what you need from script.

℉絮湮 2024-08-20 17:24:37

您可以使用 NotesDXLExporter 类导出富文本并使用 XSLT 将输出转换为您需要的内容。

You can use the NotesDXLExporter class to export the Rich Text and use an XSLT to transform the output to what you need.

说谎友 2024-08-20 17:24:37

我知道您提到过使用 LotusScript,但是如果您不介意编写一个小型 Java 代理(在 Notes 客户端中),那么这可以相当容易地完成 - 并且不需要修改现有的表单设计。

基本思想是让您的 Java 代码通过本地主机 http 请求(这在 Java 中很简单)打开特定文档,并让您的代码捕获该 html 输出并将其保存回该文档。基本上,您可以让 Domino 渲染引擎来完成繁重的工作。

您需要执行以下操作:

  1. 创建一个仅包含要转换的富文本字段的表单,内容类型为 HTML
  2. 创建一个视图,其中包含要转换的所有文档的选择公式和表单公式 URL
  3. 创建 Java 代理,它只遍历您的视图,并为每个文档获取其 docid,以 http://SERVER/your_database_path.nsf/NEW_VIEW/docid?openDocument,获取 http 响应并保存它。

我在类似的帖子中放置了一些示例代码:

如何使用lotusscript将文档中的文本和富文本字段转换为html?

I know you mentioned using LotusScript, but if you don't mind writing a small Java agent (in the Notes client), this can be done fairly easily - and there is no need to modify the existing form design.

The basic idea is to have your Java code open a particular document through a localhost http request (which is simple in Java) and to have your code capture that html output and save it back to that document. You basically allow the Domino rendering engine to do the heavy lifting.

You would want do this:

  1. Create a form which contains only the rich-text field you want to convert, and with Content Type of HTML
  2. Create a view with a selection formula for all of the documents you want to convert, and with a form formula which computes to the new form
  3. Create the Java agent which just walks your view, and for each document gets its docid, opens a URL in the form http://SERVER/your_database_path.nsf/NEW_VIEW/docid?openDocument, grabs the http response and saves it.

I put up some sample code in a similar SO post here:

How to convert text and rich text fields in a document to html using lotusscript?

抠脚大汉 2024-08-20 17:24:37

适用于 Domino 10(尚未测试 9)

HTMLStrings$ = NotesRichTextItem .Converttohtml([options] ) As String

请参阅文档:

https: //help.hcltechsw.com/dom_designer/10.0.1/basic/H_CONVERTOHTML_METHOD_NOTESRICHTEXTITEM.html

UPDATE (2022)

自版本 11 起,HCL 不再支持此方法。该文档不包含任何有关该方法的信息。
我做了一些测试,它在 v12 中仍然有效,但 HCL 建议不要使用它。

Works in Domino 10 (have not tested with 9)

HTMLStrings$ = NotesRichTextItem .Converttohtml([options] ) As String

See documentation :

https://help.hcltechsw.com/dom_designer/10.0.1/basic/H_CONVERTOHTML_METHOD_NOTESRICHTEXTITEM.html

UPDATE (2022)

HCL no longer support this method since version 11. The documentation does not include any info about the method.
I have made some tests and it still works in v12 but HCL recommended to not use it.

云柯 2024-08-20 17:24:37

Casper 的上述建议效果很好,但请确保 ACL 允许匿名访问,否则您的 HTML 将是登录表单中的 HTML

Casper's recommendation above works well, but make sure the ACL is such to allow Anonymous Access otherwise your HTML will be the HTML from your login form

与君绝 2024-08-20 17:24:37

如果您不需要专门从项目中获取 Richtext,则可以使用 ?OpenDocument,(至少)记录在此处: https://www.ibm.com/developerworks/lotus/library/ls-Domino_URL_cheat_sheet/
https:// www.ibm.com/support/knowledgecenter/SSVRGU_9.0.1/com.ibm.designer.domino.main.doc/H_ABOUT_URL_COMMANDS_FOR_OPENING_DOCUMENTS_BY_KEY.html

OpenDocument 还允许您扩展部分(我不确定 OpenField 是否这样做)

语法是:
http://Host/Database/View/DocumentUniversalID?OpenDocument

但请务必包含字符集参数 - 如果不指定 utf-8 作为字符集,日语文档将无法读取。

下面是我使用的方法,它接受 NotesDocument 并以字符串形式返回文档的 HTML。

    private string ConvertDocumentToHml(Domino.NotesDocument doc, string sectionList = null)
    {
        var server = doc.ParentDatabase.Server.Split('/')[0];
        var dbPath = doc.ParentDatabase.FilePath;
        string viewName = "0";
        string documentId = doc.UniversalID.ToUpper();

        var ub = new UriBuilder();
        ub.Host = server;
        ub.Path = dbPath.Replace("\\", "/") + "/" + viewName + "/" + documentId;

        if (string.IsNullOrEmpty(sectionList))
        {
            ub.Query = "OpenDocument&charset=utf-8";
        }
        else
        {
            ub.Query = "OpenDocument&charset=utf-8&ExpandSection=" + sectionList;
        }

        var url = ub.ToString();

        var req = HttpWebRequest.CreateHttp(url);
        try
        {
            var resp = req.GetResponse();
            string respText = null;

            using (var sr = new StreamReader(resp.GetResponseStream()))
            {
                respText = sr.ReadToEnd();
            }
            return respText;
        }
        catch (WebException ex)
        {
            return "";
        }
    }

If you do not need to get the Richtext from the items specifically, you can use ?OpenDocument, which is documented (at least) here: https://www.ibm.com/developerworks/lotus/library/ls-Domino_URL_cheat_sheet/
https://www.ibm.com/support/knowledgecenter/SSVRGU_9.0.1/com.ibm.designer.domino.main.doc/H_ABOUT_URL_COMMANDS_FOR_OPENING_DOCUMENTS_BY_KEY.html

OpenDocument also allows you to expand sections (I am unsure if OpenField does)

Syntax is:
http://Host/Database/View/DocumentUniversalID?OpenDocument

But be sure to include the charset parameter as well - Japanese documents were unreadable without specifying utf-8 as the charset.

Here is the method I use that takes a NotesDocument and returns the HTML for the doc as a string.

    private string ConvertDocumentToHml(Domino.NotesDocument doc, string sectionList = null)
    {
        var server = doc.ParentDatabase.Server.Split('/')[0];
        var dbPath = doc.ParentDatabase.FilePath;
        string viewName = "0";
        string documentId = doc.UniversalID.ToUpper();

        var ub = new UriBuilder();
        ub.Host = server;
        ub.Path = dbPath.Replace("\\", "/") + "/" + viewName + "/" + documentId;

        if (string.IsNullOrEmpty(sectionList))
        {
            ub.Query = "OpenDocument&charset=utf-8";
        }
        else
        {
            ub.Query = "OpenDocument&charset=utf-8&ExpandSection=" + sectionList;
        }

        var url = ub.ToString();

        var req = HttpWebRequest.CreateHttp(url);
        try
        {
            var resp = req.GetResponse();
            string respText = null;

            using (var sr = new StreamReader(resp.GetResponseStream()))
            {
                respText = sr.ReadToEnd();
            }
            return respText;
        }
        catch (WebException ex)
        {
            return "";
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文