2015-06-13 78 views
0

我在lotusscript代理程序中删除了附件从NotesDocuments中的以下代码。但NotesDocument.save()会导致富文本格式(字体,颜色)丢失。有什么方法可以保留格式吗?NotesDocument.save()导致富文本格式丢失

Sub removeAttachments_v2(doc As NotesDocument) 
    Dim session As NotesSession 
    Dim rtitem As Variant 
    Dim filename As String 
    Dim ans As Variant 

    Set session = New NotesSession 
    Dim richstyle As NotesRichTextStyle 
    Set richstyle = session.CreateRichTextStyle 
    richstyle.NotesColor = COLOR_BLUE 

    If doc.HasEmbedded Then 
     Set rtitem = doc.getfirstitem("Body") 
     If (rtitem.type = RICHTEXT) Then 
      ForAll object In rtitem.EmbeddedObjects 
       If (object.Type = EMBED_ATTACHMENT) Then 
        filename = object.source 
        Call object.remove 
        Call rtitem.AddNewLine(2) 
        Call rtitem.AppendStyle(richstyle) 
        Call rtitem.AppendText("Attachemnt removed: " & filename) 
        Call doc.Save(True, True , True) 
       End If 
      End ForAll 
     End If 
    End If 
End sub 

EDIT1:初始化函数

Sub Initialize 
    Dim db As New NotesDatabase("","") 
    Dim col As NotesDocumentCollection 
    Dim doc As NotesDocument 

    Call db.Open("", "C:\this\is\db\dir\test.nsf") 
    Set col = db.Alldocuments 

    Set doc = col.Getfirstdocument() 
    While Not (doc Is Nothing) 
     Call RemoveAttachments_v2(doc) 
     Call doc.Save(False, False, False) 
     Set doc = col.GetNextDocument(doc) 
    Wend 
End Sub 
+0

您对NotesSesion.ConvertMIME属性的设置是什么? –

+0

NotesSession.ConverMIME为True – PrashantB

回答

0

尽管事实,即在保存文档的每个附件我找不到任何理由,为什么发生这种情况。我只是复制你的代码的代理,并删除附件根据需要并追加在蓝色的文字...

无格式丢失......

误差必须在别的地方在你的代码,可能在调用函数中。

OLD ANSWER(错因自己的测试,这里只是不停地为历史):

这里的问题很可能是:你定义rtitem为Variant。并且 getfirstitem获取NotesItem而不是NotesRichtextItem,因此在保存时会将其转换为“纯文本”项目。

很可能您使用Variant而不是NotesRichtextItem,因为 存在MIME邮件,其中将变量定义为NotesRichtextItem 将导致“Type Missmatch”或类似错误。只要你不要 写回任何东西就行了。

为MIME邮件需要完全不同的处理,以实现自己的目标, 你应该先使用 正确类型的修为纯NotesRichtextItems的代码,然后再另写代码 - 分公司办理Mime- 项目

+0

他正在检查项目类型,如果它不返回为type = RICHTEXT,他不保存。所以我不认为它把它当作纯文本项目。 –

+0

对不起,你是对的... –

+0

@TorstenLink你可能是真的,但我仍然面临这个问题。我只能在运行此代理后才能收到纯文本电子邮件,否则邮件将为RT。 – PrashantB