Answer the question
In order to leave comments, you need to log in
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;
Answer the question
In order to leave comments, you need to log in
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";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question