从文档中的两个富文本字段中提取附件 [英] Extracting attachments from two rich text fields in a document
问题描述
我正在使用LotusScript将文档中的附件提取到用户的本地计算机.该文档有两个富文本字段Body1
和Body2
,很多时候只有其中一个带有附件.我正在使用以下代码段:
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屋!