简体   繁体   中英

Copying CSV data from a div to Excel sheet

Currently, if I have a <textarea> as follows:

<textarea>
1, 2, 3, 4
5, 6, 7, 8
9, 10, 11, 12
</textarea>

and then copy and paste the contents into Excel. Excel will give me the option to paste from a comma delimited source.

However, instead of a textarea, I would like to use a div. I have tried the following:

<div style="white-space: pre">
    1, 2, 3, 4
    5, 6, 7, 8
    9, 10, 11, 12
</div>

Now when I try to paste into Excel it does not recognize it as being a comma-delimited source.

How can I format a div so that I can copy and paste pure text from it thus allowing Excel to recognize the delimited data?

Part of my reason for not wanting to use a textarea is that I am not wanting the data to be editable. The div also grows to the correct height of the content (which the textarea does not do.)

I use LibreOffice and at least my solution works there. I copy the contents of the div, right click on the cell -> paste special -> unformatted text (ctrl + alt + shift + v) If there is such an option in LibreOfice then in Office it should be;)

 <div style="white-space: pre-wrap"> 1, 2, 3, 4 5, 6, 7, 8 9, 10, 11, 12</div>

You can also look at these solutions .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM