This is a migrated thread and some comments may be shown as answers.

Drag drop - html table to Microsoft Word (WPF)

1 Answer 102 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Prateek
Top achievements
Rank 1
Prateek asked on 16 Jun 2014, 10:43 PM
Hi,

I am trying to implement dragging & dropping  HTML table to Microsoft word document.

It is a WPF application where I am dragging a RadListBox item to word and if I am setting data objects type to "Text" then plain text is getting dropped in MS word document.  
var payload = DragDropPayloadManager.GeneratePayload(null);
payload.SetData("Text", "I am a plain text");

But my requirement is to drag and drop formatted text (with background, border, different font color).
Also, I don't want to drag and drop image as it is not going to work in my case.

Please advise.

1 Answer, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 19 Jun 2014, 10:34 AM
Hi Prateek,

What I can suggest you would be to use RTF text formatted as desired, create a new DataObject from it and assign to e.Data in the DragInitializeHandler as shown below:

string rtfString = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}}
{\colortbl ;\red0\green0\blue0;\red255\green0\blue0;}
\viewkind4\uc1\pard\qc\cf1\fs16 test \b bold \cf2\b0\i italic\cf0\i0\fs17
\par }";
 
MemoryStream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(rtfString));
e.Data = new DataObject(DataFormats.Rtf, rtfString);

Once you drop on Word the text will be formatted as defined in the rtfString.

Hope this will work for you.

Regards,
Kalin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
DragAndDrop
Asked by
Prateek
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Share this question
or