我使用以下代码将.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的数据?
答案 0 :(得分:1)
您插入一个换行符以创建大于64KB的段落。 但是,当您处理Rich Text字段时,应该使用后端类。
答案 1 :(得分:1)
使用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
要使用,
fstreamOpenFile(sFilePath, False, True)