Search code examples
javascripthtmlms-wordclipboardclipboarddata

How can I format clipboard data in Javascript to create soft line breaks when pasted into MS Word?


In Javascript, I am putting billing/shipping address data on the clipboard (using clipboard.js). When I paste that data into MS Word, it shows up with paragraph separators and looks too spread out for an address.

How can I format the data from Javascript so it shows up as if each line ended with a soft line break (press shift-Enter in MS Word) when I paste the data into MS Word?


Solution

  • I had been joining the lines with linefeed:

    copyText = copyText.join('\n');
    

    I just changed \n to \v (vertical tab):

    copyText = copyText.join('\v');