【发布时间】:2025-12-18 03:05:03
【问题描述】:
我正在尝试从 Lotus Notes 数据库(使用 Designer 7.0)导出所有文档及其附件。我可以获取文档数据并获取附件,但前提是我对名称进行了硬编码。我发现在 LotusScript 中以编程方式获取文件名的这两种方法都不起作用,如下面的两个代码块所示。第一个, doc.GetFirstItem( "Body" ) 返回 Nothing,第二个,在 Forall 行执行期间出现类型不匹配。 任何有关如何提取附件的帮助将不胜感激!我不确定附件是存储为“附件”还是 OLE,但我怀疑是附件,因为它们主要是 PDF。
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim query As String
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim fileCount As Integer
Dim attachment As NotesEmbeddedObject
Dim fileName As String
Set db = session.CurrentDatabase
' get a document that has an attachment
Set collection = db.FTSearch( "06/25/2013", 10 )
fileNum% = Freefile()
fileName$ = "c:\kcw\lotusexport.txt"
Open fileName$ For Output As fileNum%
Write #fileNum%, "docs found", collection.Count
Set doc = collection.GetFirstDocument
' write out document properties
Forall x In doc.Items
Write #fileNum%, x.Name, " = ", x.Text
End Forall
'extract document (using hardcoded name)
Set attachment = doc.GetAttachment("OCSE-FRONT_SCANTODESKTOP_06262013-104822.pdf")
Call attachment.ExtractFile _
( "c:\kcw\attachment" )
'Try to get attachment through "Body", but rtitem is Nothing
Set rtitem = doc.GetFirstItem( "Body" )
Write #fileNum%, "rtitem is Nothing", rtitem Is Nothing
fileCount = 0
If Not rtitem Is Nothing Then
If ( rtitem.Type = RICHTEXT ) Then
Write #fileNum%, "rtitem is RICHTEXT"
Forall o In rtitem.EmbeddedObjects
Write #fileNum%, "has Embedded Objects"
fileCount = fileCount + 1
Write #fileNum%,"rtitem num", fileCount
Call o.ExtractFile _
( "c:\kcw\newfile" & Cstr(fileCount) )
End Forall
End If
End If
'Fails with "Type mismatch" at Forall loop
If doc.HasEmbedded Then
Write #fileNum%, "doc has embedded"
Forall objects In doc.EmbeddedObjects
Write #fileNum%, "in for loop"
Write #fileNum%, "filename= ", object.Source
End Forall
End If
Close fileNum%
End Sub
【问题讨论】:
-
Dim session..etc 是什么意思?
-
Body 字段是否存在于每个文档中?很奇怪,它什么也不返回。
-
您绝对应该看看 LotusScript 中的错误处理技术。循环处理的文档可能会出现一些问题 - 随时。只是从头顶:不同的形式(没有正文字段),损坏的文档(.isValid),无效的文件名(内部附件名称可能与客户端中显示的不同)等等。
-
@zanbri:您需要声明您使用的 NotesObjects。任何 Notes 开发人员都会认出这些行,而您一直在编写它们。 :-)
标签: types lotus-notes attachment lotusscript type-mismatch