Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
46
rated 0 times [  50] [ 4]  / answers: 1 / hits: 21738  / 6 Years ago, tue, may 1, 2018, 12:00:00

I have a SheetJS .xlsx generated file, but I have not been able to put border to the cells.



I have this:



enter



And I need this:



enter



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>




More From » sheetjs

 Answers
110

You are using community version of SheetJS library and with this version can not do styling. BUT in Pro Version styling feature is available.



Checkout this official comment:




This is the community version. We also offer a pro version with
performance enhancements, additional features like styling, and
dedicated support.




For more information about Pro Version visit their official site: http://sheetjs.com/pro


[#54538] Thursday, April 26, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shane

Total Points: 239
Total Questions: 91
Total Answers: 114

Location: Faroe Islands
Member since Tue, Jul 7, 2020
4 Years ago
shane questions
;