Lotus notes 使用lotusscript从Lotus notes检索内联图像

Lotus notes 使用lotusscript从Lotus notes检索内联图像,lotus-notes,lotusscript,Lotus Notes,Lotusscript,我有一些NotesDocument,其中一些RichText字段同时具有文本和内联图像。我可以获取该项目的文本部分,但无法使用lotusscript检索内联图像。有谁能给我建议一种从这些文档中检索内联图像的方法吗。 LotusScript代码: Sub Click(Source As Button) Dim session As New NotesSession Dim db As NotesDatabase Dim mainDoc As NotesDocum

我有一些NotesDocument,其中一些RichText字段同时具有文本和内联图像。我可以获取该项目的文本部分,但无法使用lotusscript检索内联图像。有谁能给我建议一种从这些文档中检索内联图像的方法吗。 LotusScript代码:

Sub Click(Source As Button)
    Dim session As New NotesSession   
    Dim db As NotesDatabase   
    Dim mainDoc As NotesDocument
    Dim v As NotesView   
    Set db = session.CurrentDatabase   

    Dim fileName As String
    Dim fileNum As Integer
    fileNum% = Freefile()
    fileName$ = "D:\data.txt"
    Open FileName$ For Append As fileNum%

    Set v = db.GetView("MyView")
    Set mainDoc = v.GetFirstDocument       

    While Not ( mainDoc Is Nothing )              
        Forall i In mainDoc.Items
            If i.Type = RICHTEXT Then
                 Write #fileNum% ,    i.Name & ":" & i.text  'how the images??
            End If
        End Forall              
        Set mainDoc = v.GetNextDocument( mainDoc )  
    Wend
End Sub

谢谢。

我建议您看看Genii软件MidasLSX产品。它们提供了一个LotusScript扩展包,可以更轻松地处理LotusNotes富文本项的复杂性

否则,您可以尝试使用NotesRichTextNavigator类来访问富文本项中的图像(理论上)。关于这类事情的文档很少。我不太清楚使用该类时图像会显示什么,但假设您浏览富文本项并能够将图像作为NotesEmbeddedObject获取句柄,我知道有一种方法可以将该对象从该类保存到磁盘


另一个(疯狂的)想法是通过电子邮件发送文档,并由另一个程序接收,该程序可以更轻松地处理电子邮件正文。Notes在处理自己的富文本字段方面没有太大帮助。

Midas是最简单的方法,但它不是免费的。(从节省的总时间来看,这是非常值得的,但如果您的组织与我工作过的组织类似,那么该工具的全部成本将由拥有当前项目的计费单位承担,而不是在整个组织中摊销,并且他们可能会在同意之前更改其要求。)还有另一种方法,那就是使用导出选项ConvertNotesBitmapToGIF将数据库导出到DXL(DominoXML)。图像将在XML中显示为数据Base64编码的
元素。如果您完全在Notes环境中操作,则需要创建一个临时文档,其中富格文本字段用作NotesMiemEntity,以便在将编码图片流式传输到文件(使用NotesStream)之前将其转换为二进制。所有这些都假设您使用的是版本6或更高版本;如果您使用的是R5或更早版本,Midas或使用C API直接访问CD记录是唯一的飞行方式。

这里有一个代理,我使用它将文件从文档的richtext字段中分离出来

Option Public
Dim uidoc As notesuidocument
Dim doc As NotesDocument
Dim db As NotesDatabase
Dim obj As NotesEmbeddedObject
Dim collection As NotesDocumentCollection
Dim rt As Variant
Dim attachNames As Variant
Dim i As Integer, x As Integer
Dim j As Integer
' Agent  - Detach Attachments to C drive for later reattachment
' Copies all attachment in richtext field to personal directory.

Sub Initialize
    Dim ws As New notesuiworkspace
    Dim ses As New NotesSession
    Set db = ses.CurrentDatabase
    Set collection = db.UnprocessedDocuments
    '  get first doc in collection
    For j = 1 To collection.Count
        Set doc = collection.GetNthDocument( j )    
' ---  create array of filenames of all the attachments in the document
        i = 0
        Redim attachNames(i)
        Forall x In doc.items
            If x.name = "$FILE" Then
                attachNames(i) = x.values(0)
                i = i + 1
                Redim Preserve attachNames(i)
            End If
        End Forall

        If i > 0 Then
            Redim Preserve attachNames(i-1)
        End If

' ---  for all of the filenames in attachNames, if it exists in the rich text field, detatch them
        If doc.hasItem("richtextfieldname") Then
            Set rt = doc.GetFirstItem("richtextfieldname")
        End If
        If attachNames(0) <> "" Then
            Forall x In attachNames 
                Set obj = rt.GetEmbeddedObject( x )
                If Not( obj Is Nothing ) Then
                    Call obj.ExtractFile( "C:\path\" & Cstr(x) )
                End If
            End Forall
        End If
        Call doc.save(True, False)
    Next
End Sub
选项公共
Dim uidoc作为notesuidocument
标注文档作为注释文档
Dim db As NotesDatabase
作为NotesEmbeddedObject的Dim obj
将集合设置为备注DocumentCollection
作为变体的Dim-rt
Dim attachNames作为变体
尺寸i为整数,x为整数
作为整数的Dim j
'代理-将附件分离到C驱动器,以便以后重新连接
'将richtext字段中的所有附件复制到个人目录。
子初始化
将ws设置为新工作区
将ses设置为新备注SESSION
Set db=ses.CurrentDatabase
Set collection=db.UnprocessedDocuments
'获取集合中的第一个文档
对于j=1到collection.Count
Set doc=collection.GetNthDocument(j)
'---创建文档中所有附件的文件名数组
i=0
附件(一)
Forall x In doc.items
如果x.name=“$FILE”,则
附件(i)=x.值(0)
i=i+1
雷迪姆保存附件(一)
如果结束
端孔
如果i>0,那么
雷迪姆保护附件(i-1)
如果结束
'---对于附件中的所有文件名,如果它存在于富文本字段中,则将其删除
如果doc.hasItem(“richtextfieldname”),则
设置rt=doc.GetFirstItem(“richtextfieldname”)
如果结束
如果附件名称(0)”,则
附件中的所有x
Set obj=rt.GetEmbeddedObject(x)
如果不是(obj什么都不是),那么
调用obj.ExtractFile(“C:\path\”和Cstr(x))
如果结束
端孔
如果结束
调用doc.save(真、假)
下一个
端接头

七年后,我一直在为这件事发愁。Rod H的答案是附件,但嵌入的图像完全是另一回事

我最幸运的是@andre guirard位于此处的LotusScript Gold Collection代码:但是,这并不是全部,因为它不能处理以旧方式嵌入图像的文档。(注释更改了它存储嵌入图像的方式。)

我试图将其与此处展示的AGECOM信息结合起来:通过改变Andre的EmbeddedImage对象,无缝处理这两种格式,查看富文本字段中的嵌入图像是否真的只是指向$FILE字段的指针,如果是,则获取FileItem对象,但最终,我用尽了我的理解和选择,以至于我无法证明我在这方面花费了雇主的资源(我的时间)

因此,如果你有嵌入的图像,都包含在新的方式,我认为安德烈的代码将工作无扰。否则,我尽力了,但是我没有答案。。。我有(对我来说)一条死胡同,希望你或其他偶然发现它的人能解释我做错了什么,让我难堪

基本上,我从Andre的代码开始,用以下方式对其进行了更改

在DOMUtils中,添加以下方法:

%REM
    Function DU_GetMeOrNextSiblingWithAttr
    Description: Starting with a particular node, return that node or the next sibling with an attribute that has a particular value.
        Does not recurse into the tree; looks only at the node passed and later siblings. 
    Parameters:
        nodeStart: node to start your search with.
        targetElement: element name of desired node.
        attrName: attribute name you want to check.
        attrValue: attribute value of element you're looking for.
        flags: string-matching flags to compare attribute, e.g. 1 for case insensitive.
%END REM
Function DU_GetMeOrNextSiblingWithAttr(nodeStart As NotesDOMNode, ByVal targetElement$, ByVal attrName$, ByVal attrValue$, ByVal flags%) As NotesDOMElementNode
    Dim node As NotesDOMNode, elTmp As NotesDOMElementNode
    Set node = nodeStart
    Do Until node.Isnull
        If node.Nodetype = DOMNODETYPE_ELEMENT_NODE Then
            If node.Nodename = targetElement Then
                Set elTmp = node
                If StrComp(elTmp.Getattribute(attrName), attrValue, flags) = 0 Then
                    Set DU_GetMeOrNextSiblingWithAttr = elTmp
                    Exit Function
                End If
            End If
        End If
        Set node = node.Nextsibling
    Loop
End Function
将FileItem.New替换为以下代码:

    %REM
    Sub New
    Description: Arguments are the parsed DOM node of the element representing a
        design element, and the name of the composite item you would like to read,
        modify or create.
%END REM
Sub New(parent As FileItemParent, elNote As NotesDOMElementNode, itemName$, fileName$)
    Set m_elNote = elNote
    
    SetItem elNote, itemName$, fileName$
    

    Dim node As NotesDOMNode
    Set node = m_elNote.Parentnode
    While node.Nodetype <> DOMNODETYPE_DOCUMENT_NODE
        Set node = node.Parentnode
    Wend
    Set m_domd = node
    parent.RegisterFileItem Me ' make sure the design element knows about us.
        ' (in case someone gets smart and invokes the constructor directly
        ' instead of using the nice methods we've provided).
End Sub

%REM
    Sub SetItem
<!-- Created Dec 6, 2017 by JSmart523 -->
    If fileName$ is blank, returns the XPath equivalent of elNote/ancestor::document/item[@name=itemName$][position()=1]
    If fileName$ is not blank, returns the XPath equivalent of elNote/ancestor::document/item[@name=itemName$][object/file/@name=fileName$][position()=1]
    
    Case insensitive. Changes itemName$ and fileName$ to the correct case if found.

    Also sets Me.m_elItem to the returned NotesDOMElementNode
    Also sets Me.m_elRawData to the file contents
%END REM
Sub SetItem(elNote As NotesDOMElementNode, itemName$, fileName$)
    Dim elFile As NotesDOMElementNode
    Dim node As NotesDOMNode
    
    'set node to ancestor::document
    Set node = elNote
    Do Until node.NodeName = "document"
        Set node = node.ParentNode
    Loop
    
    'If fileName$ = "", get the first ancestor::document/item[@name=itemName$]
    'Otherwise,         get the first ancestor::document/item[@name=itemName$][/object/file/@name=fileName$]
    Set m_elItem = DU_GetChildOfType(node, DOMNODETYPE_ELEMENT_NODE)
    QualifyingItem m_elItem, itemName$, m_elRawData, fileName$
    m_itemName = itemName$
    m_fileName = fileName$
End Sub

%REM
    Sub QualifyingItem
<!-- Created Dec 8, 2017 by JSmart523 -->
    Starting with incoming elItem node, ensures it's an item we want or changes elItem to the first sibling that qualifies.
%END REM
Sub QualifyingItem(elItem As NotesDOMElementNode, itemName$, elRawData As NotesDOMElementNode, fileName$)
    Dim elFile As NotesDOMElementNode
    Dim node As NotesDOMNode
    Dim elObject As NotesDOMElementNode

    If Not elItem Is Nothing Then
        'Initially, elItem is just a starting point, not necessarily the item we want.
        'If it's an item with the right name, great, otherwise change elItem to the next sibling item with the right name. 
        Set elItem = DU_GetMeOrNextSiblingWithAttr(elItem, "item", "name", itemName$, 1)
        
        If Not elItem Is Nothing Then
            If fileName$ = "" Then
                'we have the right item, and aren't looking for a file node, which means we want the rawitemdata node
                Set elRawData = DU_getChildNamed("rawitemdata", elItem)
            Else
                'We are looking for a $FILE item that contains a file.
                'There are possibly several $FILE items within a document, one for each file. We've got the right one if ./object/file/@name = fileName$
                Do
                    Set elObject = DU_GetChildNamed("object", elItem)
                    If Not elObject Is Nothing Then
                        Set elFile = DU_GetChildWithAttr(elObject, "file", "name", fileName$, 1)
                        If Not elFile Is Nothing Then
                            'Yay! We have the right elItem node!
                            Set elRawData = DU_GetChildNamed("filedata", elFile)
                            fileName$ = elFile.GetAttribute("name")
                            Exit Do
                        End If
                    End If
                    Set elItem = DU_GetMeOrNextSiblingWithAttr(elItem.NextSibling, "item", "name", itemName$, 1)
                Loop Until elItem Is Nothing
                'At this point, either we jumped out of the loop with a valid elItem and elRawData, or elItem is Nothing
            End If
        End If
    End If
    
    If elItem Is Nothing Then
        'we didn't find the correct item
        'make sure elRawData is changed to Nothing, too.
        Set elRawData = Nothing
    Else
        itemName$ = elItem.GetAttribute("name")
    End If
End Sub
%REM
次新
描述:参数是表示
设计元素,以及要读取的复合项的名称,
修改或创建。
%终止REM
Sub-New(父级为FileItemParent,elNote为NotesDOMElementNode,itemName$,fileName$)
设置m_elNote=elNote
SetItem elNote,itemName$,文件名$
将节点变暗为NotesDOMNode
Set node=m_elNote.Parentnode
While node.Nodetype域Nodetype\u文档\u节点
设置节点=否
    %REM
    Class FileItemParent
<!-- Created Dec 5, 2017 by JSmart523 -->
    This is a base class for objects that use FileItem objects
%END REM
Class FileItemParent
    m_elElRoot As NotesDOMElementNode
    m_elFD As NotesDOMElementNode
    Public m_fileItem As FileItem
    m_fItems List As FileItem ' list of FileItems we've created and returned to caller.
    m_iMode As Integer

    %REM
        Property Get DOMElement
        Description: Return the element node representing the design element.
    %END REM
    Public Property Get DOMElement As NotesDOMElementNode
        Set DOMElement = m_elElRoot
    End Property

    %REM
        Sub New
        Arguments:
            db: the database containing the design element.
            elElement: the DOM element corresponding to the design note (e.g. the <note>
                element).
            domp: The DOM parser object containing elElement.
    %END REM
    Sub New(elElement As NotesDOMElementNode)
        Set m_elElRoot = elElement
    End Sub
    
    Sub Delete
        On Error Resume Next
        ForAll thing In m_fItems
            Delete thing
        End ForAll
    End Sub
    
    %REM
        Function HasItem
        Description: Determine whether there's an item element in the note DXL with a
            given item name.
            Note that the presence of an item doesn't guarantee it's formatted as a file
            CD record.
    %END REM
    Function HasItem(ByVal itemName$) As Boolean
        HasItem = Not (DU_GetChildWithAttr(m_elElRoot, "item", "name", itemName, 1) Is Nothing)
    End Function

    
    %REM
        Function RegisterFileItem
        Description: For internal use -- lets the FileItem class notify us that it's
            referencing our DOM tree so that we can delete the object if we erase the
            corresponding item element.
    %END REM
    Sub RegisterFileItem(x As FileItem)
        Set m_fItems(LCase(x.itemName)) = x
        If m_FileItem Is Nothing Then
            Set m_FileItem = x
        End If
    End Sub
    
    %REM
        Function GetFileItem
        Description: Retrieve the FileItem object associated with a CD-record item.
            An object will be returned even if the item doesn't exist, which you can
            use to create the item via UpdateFile method.
    %END REM
    Function GetFileItem(itemName$, fileName$) As FileItem
        Set GetFileItem = New FileItem(Me, m_elElRoot, itemName, fileName)
    End Function
    
End Class
%REM
    Sub InitFileItem
<!-- Created Dec 6, 2017 by JSmart523 -->
    Called by New
%END REM
Sub InitFileItem()
    Dim buffer As Variant 'byte array
    Dim iFileNameLen As Integer
    Dim sFileName As String
    Dim sItemName As String
    Dim stream As NotesStream
    
    If Len(m_b64) < 30000 Then
        'If content is short then maybe it's a link to a $FILE item instead of the actual content?
        Dim session As New NotesSession
        Set stream = session.CreateStream()
        Base64ToBinary m_b64, stream
        stream.Position = 0
        buffer = stream.Read(1)
        If buffer(0) = 196 Then
            'this is a link to a $FILE, not the actual image contents!
            
            stream.Position = 10
            buffer = stream.Read(2)
            iFileNameLen = ConvertWordByteArray(buffer)
            
            stream.Position = 24
            buffer = stream.Read(iFileNameLen)
            sFileName = BytesToString(buffer)
            sItemName = "$FILE"
            
            GetFileItem sItemName, sFileName 'sets m_fileItem to a FileItem object
        End If
    End If
End Sub

%REM
    Property Get SuggestedFileName
%END REM
Public Property Get SuggestedFileName As String
    If m_fileItem Is Nothing Then
        SuggestedFileName = "Embedded-" + ItemName + "." + SuggestedFileType
    Else
        SuggestedFileName = m_fileItem.FileName
        If InStr(SuggestedFileName, ".") = 0 Then
            SuggestedFileName = SuggestedFileName + "." + SuggestedFileType
        End If
    End If
End Property

%REM
    Property Get SuggestedFileType
%END REM
Public Property Get SuggestedFileType As String
    If ImageType = "notesbitmap" Then
        SuggestedFileType = "bmp"
    Else
        SuggestedFileType = ImageType
    End If
End Property

%REM
    Sub ReadFileToStream
%END REM
Sub ReadFileToStream(streamOut As NotesStream)
    If m_FileItem Is Nothing Then
        ReadToStream streamOut
    Else
        Set m_FileItem.Stream = streamOut
        m_FileItem.Load
    End If
End Sub