tags:

views:

147

answers:

2

On my webpage I want to able to present tabular data and give the user the possibility to copy it directly into excel. This however doesn't work, all of the data is pasted in one cell:

<table>
<tr><td>Column 1</td><td>Column 2</td></tr>
<tr><td>Data 1.1</td><td>Data 2.1</td></tr>
<tr><td>Data 1.2</td><td>Data 2.2</td></tr>
</table>

How to present this data so it can be copied directly into excel.

+1  A: 

I just thought of the solution while typing out the question. You need to specify the table body:

<table>
<tbody>
<tr><td>Column 1</td><td>Column 2</td></tr>
<tr><td>Data 1.1</td><td>Data 2.1</td></tr>
<tr><td>Data 1.2</td><td>Data 2.2</td></tr>
</tbody>
</table>
Pim Jager
learned something new :)
Martijn Laarman
+1  A: 

This works with IE, but unfortunately others browsers (the below is for Firefox) require some user effort:

  • In Excel select 'Paste special' the 'Text', although column alignment is then screwed when a cell is null
  • Use the Table2Clipboard extension

Just as an aside, the column heading should be inside a <thead> of course:

<table>

<thead>

<tr>
<th scope="col">Column 1</th>
<th scope="col">Column 2</th>
</tr>

</thead>

<tbody>

<tr>
<td>Data 1.1</td>
<td>Data 2.1</td>
</tr>

<tr>
<td>Data 1.2</td>
<td>Data 2.2</td>
</tr>

</tbody>

</table>
The Wilky Bar Kid