问题
I'd like to insert the text string into the existing rich text field data at the first position for all of documents in a DB. NotesRichTextNavigator.FindFirstElement method - This method needs to specify the element type to search but I simply insert the text at the first position of the rich text data. This might be very basic question, but I could not find the way and waste a few hours... Please help me!
回答1:
You can do this using a workaround. Instead of working with FindFirstElement, you create a dummy richtextitem, containing the text that you need to prepend to your original item, add the original item to the dummy item, delete the original item and recreate it. Then add the dummy item and delete the dummy.
This sounds complex, but it is not that hard actually. Here's a small example in LotusScript on how to do this on a document:
'Get your richtext field
Set rtf = doc.getfirstItem("myRTF")
'create the dummy
Set rtDummy = doc.Createrichtextitem("rtfDummy")
'set the text that you want to insert in your richtext field
Call rtDummy.appendText("Inserting a line of text at the top")
'Add a line to make sure the inserted text is on a separate paragraph
Call rtDummy.Addnewline(1, true)
'Add the content of the original richtext item
Call rtDummy.Appendrtitem(rtf)
'Remove the original item and recreate it
Call rtf.Remove()
Set rtf = doc.Createrichtextitem("myRTF")
'Append the dummy item (including the added text)
Call rtf.Appendrtitem(rtDummy)
'Remove the dummy item
Call rtDummy.Remove()
'Save the document
Call doc.Save(True, True)
来源:https://stackoverflow.com/questions/58804964/notesrichtexitem-insert-text-strings-at-the-first-position-in-existing-rich-te