【问题标题】:Adding more than 64KB to an IBM (Lotus) Notes rich text field, using Lotusscript使用 Lotusscript 向 IBM (Lotus) Notes 富文本字段添加超过 64KB
【发布时间】:2018-08-03 03:31:47
【问题描述】:

我使用以下代码将 .log(文本)文件的内容拉入 Notes 富文本字段,但如果数据量 > 64 KB,则会失败:

Dim io As Integer
Dim text As String
Dim fileSize As Single

io = Freefile
fileSize = 0

Open f For Input As io
fileSize = Filelen( f )

If (fileSize > 65536) Then
    Msgbox "Sorry, but the file " + f + " is > 64KB and cannot be rendered in the default rich text field.",, "Can't continue"
    Close #io
    Exit Sub
End If

While Not(Eof(io))
    Line Input #io, text
    Call uid.FieldAppendText("RT1", text + Chr(13) + Chr(10))
Wend

Close #io

我检查文件大小以避免错误(这是一个段落不能超过 64KB 的抱怨)。那么如何添加多个段落,从而可以显示超过 64KB 的数据呢?

【问题讨论】:

    标签: lotus-notes lotusscript


    【解决方案1】:

    您插入换行符以创建大于 64KB 的段落。 但是当您操作富文本字段时,您应该使用后端类。

    【讨论】:

      【解决方案2】:

      使用NotesStream一次读取一行,然后使用NotesRichTextItem的AppendText和AddNewLine(1, True)

      下面的 subImportStreamToRT 子例程未经测试,所以墨菲定律说这里有一个大的地方,但至少它编译!祝你好运!

      Option Public
      Option Declare
      %Include "lserr.lss"
      
      %REM
          Function fstreamOpenFile(sPath As String, bTruncate As Boolean, bConfirmExists As Boolean) As NotesStream
      <br>
          <b>Arguments</b>
          <blockquote><dl><dt>sPath</dt><dd>Filepath of the file to be opened/created.</dd>
          <dt>bTruncate</dt><dd>Boolean. True if file is for output and any existing file should be replaced rather than appended to.</dd>
          <dt>bConfirmExists</dt><dd>Boolean. If True, and the opened file is empty, then an ErrFileNotFound error will be thrown.</dd></dl></blockquote>
      %END REM
      Public Function fstreamOpenFile(sPath As String, bTruncate As Boolean, bConfirmExists As Boolean) As NotesStream
          Dim bFlag As Boolean
          Dim session As New NotesSession
          Dim stream As NotesStream
      
          If sPath = "" Then Error 13, "No path supplied."
          Set stream = session.Createstream()
          If Not stream.Open(sPath) Then Error ErrOpenFailed, {Could not open file at "} + sPath + {"}
          If bConfirmExists And stream.Bytes = 0 Then Error ErrFileNotFound, {File at "} + sPath + {" is missing or empty.} 
          If bTruncate Then Call stream.Truncate()
          Set fstreamOpenFile = stream
      End Function
      
      %REM
          Sub subImportStreamToRT(stream As NotesStream, rt As NotesRichTextItem)
          For each line of text in the stream, appends that text in its own paragraph.
          Assumes that the first line of text can simply be appended without first creating a new paragraph. (e.g. rt is a blank field or you've already added a new line before calling this function)
      <br>
          <b>Arguments</b>
          <blockquote><dl><dt>stream As NotesStream</dt><dd>NotesStream containing text to be imported into a rich text file</dd>
          <dt>rt As NotesRichTextItem</dt><dd>NotesRichTextItem to import stream's text into.</dd></dl></blockquote>
      %END REM
      Sub subImportStreamToRT(stream As NotesStream, rt As NotesRichTextItem)
          If Not stream.IsEOS Then
              Do
                  rt.AppendText stream.ReadText(STMREAD_LINE, EOL_ANY)
                  If stream.IsEOS Then
                      Exit Sub
                  Else
                      rt.AddNewLine 1, True
                  End If
              Loop
          End If
      End Sub
      

      使用,

      1. 将 NotesStream 变量设置为 fstreamOpenFile(sFilePath, False, True)
      2. 获取/创建 NotesRichTextItem 对象
      3. 将 NotesStream 和 NotesRichTextItem 对象传递给 subImportStreamToRT
      4. 保存您的 NotesDocument
      5. 试一试并调试代码,因为 subImportStreamToRT 未经过测试。

      【讨论】:

      • 基本上,是 AddNewline 方法的第二个参数执行此操作。检查文档。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多