从文档中的两个富文本字段中提取附件 [英] Extracting attachments from two rich text fields in a document

查看:198
本文介绍了从文档中的两个富文本字段中提取附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LotusScript将文档中的附件提取到用户的本地计算机.该文档有两个富文本字段Body1Body2,很多时候只有其中一个带有附件.我正在使用以下代码段:

I am extracting attachments in a document to user's local machine using LotusScript. The document has two rich text fields Body1 and Body2 and many a times only one of them has an attachment in it. I am using the below code snippet:

Dim doc As NotesDocument
Dim richTextItem As NotesRichTextItem
.....
.....
If doc.Hasembedded Then
    Set richTextItem = doc.Getfirstitem("Body1")
    ForAll o In richTextItem.Embeddedobjects
        Call o.ExtractFile(dirName + "\" + o.Name)
    End ForAll

    Set richTextItem = doc.Getfirstitem("Body2")
    ForAll o In richTextItem.Embeddedobjects
        Call o.ExtractFile(dirName + "\" + o.Name)
    End ForAll
End If

问题在于,如果Body1中没有附件,而Body2确实存在附件,则上述代码在语句ForAll o In richTextItem.Embeddedobjects上引发Type mismatch的错误,反之亦然,因为在该富文本中没有嵌入的对象物品. doc.Embeddedobjects也不起作用,因为富文本项中存在附件.并且NotesRichTextItem类不具有Hasembedded属性,该属性可用于检查其中是否存在附件.

The problem is that if Body1 does not have attachment in it and Body2 does then the above code throws error of Type mismatch on statement ForAll o In richTextItem.Embeddedobjects and vice versa as there are no embedded objects in that rich text item. Also doc.Embeddedobjects does not work because attachments are present inside rich text items. And the NotesRichTextItem class does not have Hasembedded property which can be used to check presence of attachments in it.

怎么办呢?

推荐答案

尝试以下方法:

Dim doc As NotesDocument
.....
.....
If doc.Hasembedded Then
    Set richTextItem = doc.Getfirstitem("Body1")
    Set rtnav = richTextItem.CreateNavigator

    If rtnav.FindFirstElement(RTELEM_TYPE_FILEATTACHMENT) Then
        Do
            Set att = rtnav.GetElement()
            filepath$ = dirName + "\" + att.Source
            Call att.ExtractFile(filepath$)      
        Loop While rtnav.FindNextElement()
    End If

    Set richTextItem = doc.Getfirstitem("Body2")
    Set rtnav = richTextItem.CreateNavigator

    If rtnav.FindFirstElement(RTELEM_TYPE_FILEATTACHMENT) Then
        Do
            Set att = rtnav.GetElement()
            filepath$ = dirName + "\" + att.Source
            Call att.ExtractFile(filepath$)      
        Loop While rtnav.FindNextElement()
    End If
End If

您可能还希望将冗余逻辑提取到子例程中.

You may also want to extract the redundant logic into a subroutine.

这篇关于从文档中的两个富文本字段中提取附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆