I have a SheetJS .xlsx generated file, but I have not been able to put border
to the cells
.
I have this:
And I need this:
Is there a way to do it with SheetJS
? It will be cool if there's a way to apply another cell styles, like background color.
EDIT:
I'm making the sheets with this function:
function makeSheet(wb, day){ //sheet for a specific day
var ws = XLSX.utils.table_to_sheet(document.getElementById(table+day));
wb.SheetNames.push(day);
wb.Sheets[day] = ws;
//columns width working ok
wb[Sheets][day][!cols] = [{ wpx : 70 },{ wpx : 121 }];
//wb[Sheets][day][A1][s] = {border:1px}; //I've tried this but doesn't work
return wb;
}
EDIT 2
I've created this example snippet, if you can put borders and/or another cell style here, that's going to be a victory:
$(document).ready(myMain);
function myMain(){
$(document).on(click,#btnexcel, function(){makeExcel()});
}
function s2ab(s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i=0; i<s.length; i++) view[i] = s.charCodeAt(i) & 0xFF;
return buf;
}
function makeExcel(){
var wb = XLSX.utils.table_to_book(document.getElementById(myTable),{sheet:Sheet 1}) //my html table
var wbout = XLSX.write(wb, {bookType:'xlsx', bookSST:true, type: 'binary'});
saveAs(new Blob([s2ab(wbout)],{type:application/octet-stream}), 'MyExcel.xlsx');
}
<!-- JQuery -->
<script src=https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js></script>
<!-- Bootstrap CSS-->
<link rel=stylesheet href=https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css>
<!-- Bootstrap JavaScript -->
<script src=https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js></script>
<script lang=javascript src=https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.12.13/xlsx.full.min.js></script>
<script src=https://fastcdn.org/FileSaver.js/1.1.20151003/FileSaver.min.js></script>
<button id=btnexcel>Download excel</button>
<table id=myTable border=1>
<thead><tr><th>hello</th><th>dear community</th></tr></thead>
<tbody>
<tr><td>I need borders</td><td>around here</td></tr>
<tr><td>I'll be glad</td><td>if you help me</td></tr>
</tbody>
</table>