2
I have a table with 5 columns, whereas the first one has a check box and the last one has a button to delete that particular row.
The issue is that I want to export to Excel, in a file .xsl
, but without the first and last column, consisting only: ID
, name
and house
. See below the export code:
$("#export").click(function(e) {
var type = 'data:application/vnd.ms-excel';
var _div = document.getElementById('table_wrapper');
var _html = _div.outerHTML.replace(/ /g, '%20');
var a = document.createElement('a');
a.href = type + ', ' + _html;
a.download = 'export_got_' + Math.floor((Math.random() * 9999999) + 1000000) + '.xls';
a.click();
});
table, tbody{
border-style: solid;
border-width: 1px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<div id="table_wrapper">
<table cellspacing="5" cellpadding="0" bordercolor="#ccc" id="list">
<tbody>
<tr class="header">
<th><input id="checkBox" type="checkbox"></th>
<th> ID</th>
<th> name</th>
<th> house</th>
<th> action</th>
</tr>
<tr>
<td><input id="checkBox" type="checkbox"></td>
<td>1</td>
<td>Jon Snow</td>
<td>Stark</td>
<td><a href='#'>Eliminar</a></td>
</tr>
<tr>
<td><input id="checkBox" type="checkbox"></td>
<td>2</td>
<td>James</td>
<td>Lennister</td>
<td><a href='#'>Eliminar</a></td>
</tr>
<tr>
<td><input id="checkBox" type="checkbox"></td>
<td>3</td>
<td>Arya</td>
<td>Stark</td>
<td><a href='#'>Eliminar</a></td>
</tr>
<tr>
<td><input id="checkBox" type="checkbox"></td>
<td>4</td>
<td>Cercei </td>
<td>Lennister</td>
<td><a href='#'>Eliminar</a></td>
</tr>
<tr>
<td><input id="checkBox" type="checkbox"></td>
<td>5</td>
<td>Daenerys </td>
<td>Targaryen</td>
<td><a href='#'>Eliminar</a></td>
</tr>
</tbody>
</table>
</div>
<br />
<button id="export">XABLAU</button>
How can I generate a file .xls
omitting some columns?
I think it malfunctioned with the first column. xD
– viana
@acklay I read the wrong question, corrected.
– Guilherme Nascimento
@acklay simplify the selectors
– Guilherme Nascimento
That’s right Guilherme! Vlw. Just one more question. When the xls file is generated, when I open it in Excel it goes with the white background. You could export with standard Excel background?
– viana
@acklay actually this file that you are doing is not Excel for real, but has how to convert relatively easy, so I have a spare time I edit the answer.
– Guilherme Nascimento
Blz bro! Abs. Vlw.
– viana
It is very difficult to export only the selected ones. I think I will open another question later. xD
– viana
@acklay remembered that I had a jquery plugin for this, I edited the answer.
– Guilherme Nascimento
Now I get it! that way I was just creating a file that would be readable using Excel, just by using table and also by extension .xls. Thanks again bro. Abs;
– viana