0

I have a problem I'm trying to solve, namely that I'd like to be able to paste the contents of the clipboard (filled using clipboard.js i) to Excel with some cells having two rows.

I won't bore you with the ins and outs of my project, but here's a simplified version:

Currently my clipboard.js implementation iterates through a javascript object pulling stuff out. I'm building it so that it can be pasted in to excel - tab separated with \t and each 'row' ends with a \n.

For example, the clipboard string for a row looks like this (spaces and variable names for readability):

"avatar\t date\t text\t time\n"

...which when pasted in to Excel produces, as expected, avatar, date, time and text in their own cells - great.

What I want to do though is have multiple rows per cell. For example, the 'alpha' column will hold two things - an avatarImage, and avatarName.

Now obviously I can't use (spaces for readability):

avatarImage\n avatarName\t date\t time\t text

...because that puts avatarImage in row 1 and the rest on row 2.

I'm fairly new to software development so I lack the wizardry to see a solution to this as yet, but I don't doubt there is a way.

Does anyone have any suggestions or ideas? Honestly anything at all would be much appreciated.

Cheers, Dave

DMcCallum83
  • 498
  • 3
  • 13

1 Answers1

0

The js assignment would look like:

 var s = '"avatarImage\n avatarName"\t date\t time\t text';

Here's the VBA equivalent (how I tested that clipboard string): running this then pasting into A1 gives the output shown.

Sub Tester()
   ''Add reference to: Microsoft Forms 2.0 Object Library
    Dim d As New DataObject 

    d.SetText """a" & vbLf & "b""" & vbTab & "c"
    d.PutInClipboard

End Sub

enter image description here

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • Awesome Tim, thank you so much for sharing that. It's in VBA but there must be a way to replicate in JS. – DMcCallum83 Oct 14 '16 at 06:26
  • I'm happy to accept your example as an answer, but I'll leave the question open for a few more hours just in case a JS ninja comes along :) – DMcCallum83 Oct 14 '16 at 06:33
  • Oh wow, that's really interesting; I hadn't thought of something simple as wrapping them in quotes. I'll test after tea, many thanks for the update. – DMcCallum83 Oct 14 '16 at 17:11