P
P
pimanov32020-06-18 14:16:30
C++ / C#
pimanov3, 2020-06-18 14:16:30

How to keep text formatting when transferring from richTextBox to Word?

How to keep text formatting when transferring from richTextBox to Word?
using Word = Microsoft.Office.Interop.Word;

Word.Application wordApp = new Word.Application();
Word.Document wordDoc = wordApp.Documents.Add();

//заполняем документ текстом
Word.Paragraph par = wordDoc.Paragraphs.Last;
par.Range.Text = richTextBox1.Text;

wordApp.Visible = true;

5eeb4bf7bfbac375056775.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Korotenko, 2020-06-18
@pimanov3

As mentioned above, copy with the mouse and everything will turn out.
If you want to understand, see the description at the link, the receiver program usually selects the oldest option from the clipboard or offers options on how to paste.
https://docs.microsoft.com/en-us/windows/win32/dat...

for (int i = 0; i < foundList.Count; i++)
{
    oPara[i] = oDoc.Content.Paragraphs.Add();
    string tempS = foundList[i].Paragraph;
    tempS = tempS.Replace("\\pard", "");
    tempS = tempS.Replace("\\par", "");
    Clipboard.SetText(tempS, TextDataFormat.Rtf);
    oPara[i].Range.InsertParagraphAfter();
    oPara[i].Range.Paste();
    oPara[i].KeepTogether = -1;
    oPara[i].Range.Font.Size = 10;
    oPara[i].Range.Font.Name = "Arial";
}

F
freeExec, 2020-06-18
@freeExec

An easy way is to copy-paste and the Word will figure it out there. Otherwise, you need to recreate all the attributes of a paragraph, word, character.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question