1

我正在尝试从 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
4

4 回答 4

4

这将为您提供文档中所有附件的列表

objects =  Evaluate("@AttachmentNames", doc)
于 2013-09-24T21:16:46.240 回答
1

我发现您的代码存在一些问题。首先,就像其他人已经说过的那样,您需要添加错误处理。其次,使用 NotesEmbeddedObject 类的 Source 属性获取附件的原始文件名。当然,您必须自己编写代码来处理重复项。

这是我编写的程序中的几行代码。

Forall i In doc.Items
  ' *** Locate attachments and detach them
  If Left$(i.Name,1)<>"$" Or Lcase(i.Name)="$file" Then
    If i.IsSummary = False Then
      If Not Isempty(i.EmbeddedObjects) Then
        If ( i.Type = RICHTEXT ) Then
          Forall obj In i.EmbeddedObjects
            If ( obj.Type = EMBED_ATTACHMENT ) Then
              Call obj.ExtractFile(basePath & obj.Source)  
            End If
          End Forall
        End If
      End If
    End If
  End If
End Forall

该程序会将数据库中的所有文档导出为 XML,分离任何附件,导出任何嵌入的图像,并将这些分离/导出的文件链接到 XML 文件。您可以在此处了解更多信息:http ://www.texasswede.com/websites/texasswede.nsf/Page/Notes%20XML%20Exporter

于 2013-09-25T14:31:00.567 回答
0

我注意到您没有引用导致错误的行。最好的 addecrror 捕获以获取错误发生在哪一行的信息:

在程序的顶部(第一行?)..

Sub Click(Source As Button)  
On error goto handler

在子的底部...

fin:
exit sub

handler:
msgbox "Error " & Error$ & " line " & Erl 
resume fin

结束子

在诊断问题时有很大帮助。

于 2013-09-25T11:03:22.610 回答
0

我是 Notes 的新手,所以感谢所有关于使代码更好的输入和解决方案!我使用以下代码进行了快速测试,发现它至少适用于一个文档(整个数据库上的待定)。我发现文件名存储在 $FILE 项中的 Items 中。此代码获取文件名,然后提取文件:

Dim item As NotesItem
 'assumes first item is $FILE
Set item = doc.Items( 0 )
Dim attachmentName As String
attachmentName = item.Values(0)
Write #fileNum%, "attachmentName= ", attachmentName
Set attachment = doc.GetAttachment(attachmentName)
Call attachment.ExtractFile _
( "c:\kcw\" + attachmentName)
于 2013-09-25T20:47:08.247 回答