Pasting to anbd from clipboard
-
How to I paste text to and from clipboard while preserving the formating. Because when I paste from the clipboar, the text that use to be bol is not, etc... Say from 1 textbox into another. Or from a textbox into a word document. Thanks
I would suggest you read through the Clipboard Class[^]. - Nick Parker
My Blog | My Articles -
I would suggest you read through the Clipboard Class[^]. - Nick Parker
My Blog | My ArticlesI got it to copy, my question is that why it still looses format. Storing Info: IDataObject d = Clipboard.GetDataObject(); //d.SetData(DataFormats.Rtf, true, richTextBox1.Text); // d.SetData(DataFormats.Rtf, richTextBox1.Rtf); Clipboard.SetText(richTextBox1.Text, TextDataFormat.Rtf); Retriving info: foreach (Word.Shape bkMark in aDoc.Shapes) { if (bkMark.TextFrame.TextRange.Text.Contains("heading")) { // bkMark.TextFrame.TextRange.Paste(); bkMark.TextFrame.TextRange.Text = Clipboard.GetText(TextDataFormat.Rtf).ToString(); //Clipboard.GetDataObject().GetData(DataFormats.Text).ToString(); // // } }
-
I got it to copy, my question is that why it still looses format. Storing Info: IDataObject d = Clipboard.GetDataObject(); //d.SetData(DataFormats.Rtf, true, richTextBox1.Text); // d.SetData(DataFormats.Rtf, richTextBox1.Rtf); Clipboard.SetText(richTextBox1.Text, TextDataFormat.Rtf); Retriving info: foreach (Word.Shape bkMark in aDoc.Shapes) { if (bkMark.TextFrame.TextRange.Text.Contains("heading")) { // bkMark.TextFrame.TextRange.Paste(); bkMark.TextFrame.TextRange.Text = Clipboard.GetText(TextDataFormat.Rtf).ToString(); //Clipboard.GetDataObject().GetData(DataFormats.Text).ToString(); // // } }
bkMark.TextFrame.TextRange.Text
contains plain text by definition, if you want formatted text you'll have to use clipboard pasting. To have control over what will actually get pasted you'll have to specify that you want RTF. IIRC there's aPasteSpecial
(or something similar) where you can tell Word what format to paste. Regards, mav