Drag drop - html table to Microsoft Word (WPF)

2 posts, 0 answers
  1. Prateek
    Prateek avatar
    3 posts
    Member since:
    Jun 2011

    Posted 16 Jun 2014 Link to this post


    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.
  2. Kalin
    Kalin avatar
    1283 posts

    Posted 19 Jun 2014 Link to this post

    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.

    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.
Back to Top