Domino 9 und frühere Versionen > ND6: Entwicklung

RichText in RichText EINFÜGEN

<< < (14/14)

eknori (retired):
Update:

In der c++ API 3.0 gibt es ü brigens eine Methode LNRichText::Insert. Damit läßt sich plain text, richtext und Objekte an eine beliebige Stelle in einem RTFeld einfügen. Und wenn ich das richtig verstehe, ist das auch im Backend möglich.

Bevor jetzt hier aber alle "Hurra" schreien; da ist noch eine Menge drumherum zu programmieren.
Sollte mein Laptop jemals mal geliefert werden, werde ich mich mal an die Umsetzung machen.

Ach ja, die API stellt auch eine methode zur verfügung um zu testen, ob ein RTFeld leer ist. Da wurde, glaube ich, hier und anderswo auch schon häufiger nach gefragt.

eknori (retired):
Habe heute ein bisschen mit der API herungespielt. Herausgekommen ist folgender Code, der den Inhalt aus einem Richtextfeld in ein anderes Richtextfeld an einer bestimmten Stelle einfügt. Die Einfügemarke ist "<RTINSERT>".

Der Code ersetzt alles Vorkommen von <RTINSERT> mit dem Inhalt des RTFeldes aus einem anderen Dokument.

Das Ganze ist selbstverständlich keine komplette Lösung, die man jetzt sofort in seine eigenen Anwendungen kopieren kann.


--- Code: ---/*
Insert richtext into richtext
Ulrich Krause, 2006
*/

#include <LNCPPAPI.H>
#include <iostream>
using namespace std; // VS2003 uses namespaces so add this line. You could prefix cout with std::cout instead.

int main(int argc, char *argv[])  {

char errorBuf [LNERROR_MESSAGE_LENGTH];

LNNotesSession s;
LNDatabase db;
LNDocument docA;
LNDocument docB;
LNDocumentArray col;
LNRichText rtA;
LNRichText rtB;
LNRTCursor cursor;
LNSTATUS   lnstatus = LNNOERROR;

LNSetThrowAllErrors( TRUE ); // get the API to trow catchable errors rather than return a status code from each operation.

try {

s.Init();
s.GetDatabase("richtext.nsf", &db, "");
db.Open();

db.GetDocuments(&col); // Get All documents in the database
docA = col[0]; // Get First Document
docB = col[1]; // Get Second Document
docA.Open(); // Open Document
docB.Open(); // Open Document
docA.GetItem("Body", &rtA); // Get Body Field
docB.GetItem("Body", &rtB); // Get Body Field
//Get a cursor pointing at the first element in the rich text.
rtA.GetCursor(&cursor);

lnstatus = cursor.GotoFirst ( "<RTINSERT>" );

//Loop through the end of the document.
while ( lnstatus != LNWARN_NOT_FOUND)
{
//Delete the original text string.
rtA.Delete( &cursor, 10);
//Replace the text string with the new one.
rtA.Insert( rtB ,&cursor);
//We have to save the doc before doing the next step
docA.Save();
//Go find the next string occurrence.
lnstatus = cursor.GotoNext( "<RTINSERT>" );
}

docA.Close();
docB.Close();
}

catch (LNSTATUS error ) {

LNGetErrorMessage( error, errorBuf);
cout << "Error: " << errorBuf << endl;

}

db.Close();
s.Term();
return 0;
}
--- Ende Code ---

Die Bilder zeigen das Dokument mit der Einfügemarke, den RT, der eingefügt werden soll und das Ergebnis.
Es werden alle Objekte eingefügt, alle Formatierungen bleiben erhalten.

eknori (retired):
Der guten Ordnung halber hier noch die komplette Lösung zum Download http://www.eknori.de/archives/348

Navigation

[0] Themen-Index

[*] Vorherige Sete

Zur normalen Ansicht wechseln