首页 文章

Lotus Notes:从视图中,如何以表或列表格式将列值插入到 e-mail 主体内容中

提问于
浏览
1

我想知道如何将视图中的列值插入电子邮件内容并将其发送?

我有这个代理,它从视图中获取前 10 个文档,将 10 个文档的特定列值导出到.xls 或.ods 文件。然后,该文件将被附加到 e-mail 的主体上。现在,我还要将列表(以表格格式或列表格式)包括在内容 e-mail 的正文中。应该采取什么方法?

帮助将不胜感激。

3 回答

  • 2

    我将使用在此描述的方法:http://blog.texasswede.com/dynamic-tables-in-classic-notes/

    基本上,您要做的是创建一个表单,在其中放置要显示在每一行上的字段。然后,在代码中循环浏览 Notes 文档集合,并为每个文档创建一个行模板文档,填充其中的字段并将该文档作为富文本格式呈现到电子邮件的正文(富文本)字段中。

  • 1

    使用NotesViewNavigator类从具有GetFirstDocumentGetNextDocument的视图中读取前 10 个文档。用notesViewEntry.ColumnValues读取列值。

    将值写入 RichText 表。这是如何创建和填充它:

    Dim body As New NotesRichTextItem(doc, "Body")
      REM Create table in Body item
      rowCount% = 4
      columnCount% = 3
      Call body.AppendTable(rowCount%, columnCount%)
      REM Populate table
      Dim rtnav As NotesRichTextNavigator
      Set rtnav = body.CreateNavigator
      Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL) 
      For iRow% = 1 To 4 Step 1
        For iColumn% = 1 To 3 Step 1
          Call body.BeginInsert(rtnav)
          Call body.AppendText("your value from row's column")
          Call body.EndInsert
          Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
        Next
      Next
    
  • 0

    您可以使用MIME并通过HTML功能生成 e-mail 的内容,例如,可以在 e-mail 中生成此表:

    <table>
       <th><td>Header 0</td><td>Header 1</td><td>Header 2</td></th>
       <tr><td>Value0 0</td><td>Value1 0</td><td>Value2 0</td></tr>
       <tr><td>Value0 1</td><td>Value1 1</td><td>Value2 1</td></tr>
       <tr><td>Value0 2</td><td>Value1 2</td><td>Value2 2</td></tr>
    </table>
    

    这是示例:

    Dim ses As New NotesSession
    Dim db As NotesDatabase
    Dim coll As NotesDocumentCollection
    Dim doc As NotesDocument
    Dim mailDoc As NotesDocument    
    Dim stream As NotesStream
    Dim body As NotesMIMEEntity
    Dim child As NotesMIMEEntity
    
    Set db = ses.CurrentDatabase   
    
    html$={<table>
        <th><td>Header 0</td><td>Header 1</td><td>Header 2</td></th>
    }
    
    'Get your document collection:
    'Set coll = ...
    
    'Generate table content:
    Set doc = coll.GetFirstDocument
    
    Do While Not doc Is Nothing
        html$ = html$ & {
        <tr><td>} & doc.Field0(0) & {</td><td>} & doc.Field1(0) & {</td><td>} & doc.Field2(0) & {</td></tr>}
    
        Set doc = coll.GetNextDocument(doc)
    Loop
    
    html$ = html$ & {
    </table>}
    
    'Generate excel file:
    'fileName$ = "SomeFile.xlsx"
    'filePath$ = "C:\SomeFolder\" & fileName$
    
    'Create mail document:
    Set mailDoc = db.CreateDocument
    mailDoc.Subject = subject$
    mailDoc.SendTo = mails
    
    ses.ConvertMIME = False
    
    'Add html to mail body:
    Set stream = ses.CreateStream
    Set body = mailDoc.CreateMIMEEntity
    Call stream.WriteText(html$)
    Call body.SetContentFromText(stream, "text/html; charset=UTF-8", ENC_IDENTITY_8BIT)
    
    'Add attachment:
    Set child = body.CreateChildEntity 
    Set header = child.CreateHeader("Content-Disposition") 
    Call header.SetHeaderValAndParams(|attachment; filename="| & fileName$ &|"|) 
    
    Set stream = ses.CreateStream 
    stream.Open filePath$, "binary" 
    child.SetContentFromBytes stream, "application/octet-stream", ENC_IDENTITY_BINARY
    child.EncodeContent ENC_BASE64
    
    Call mailDoc.CloseMIMEEntities(True, "Body")
    
    'Send mail:
    Call mailDoc.Send(False)
    

相关问题