如何将单元格边框添加到 SheetJS .xlsx 生成的文件?

How to add cell border to SheetJS .xlsx generated file?

我有一个 SheetJS .xlsx 生成的文件,但我无法将 border 放入 cells

我有这个:

我需要这个:

有没有办法用 SheetJS 做到这一点?如果有办法应用其他单元格样式,比如背景颜色,那就太棒了。

编辑:

我正在用这个功能制作表格:

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;
}

编辑 2

我已经创建了这个示例片段,如果你可以在这里放置边框 and/or 另一个单元格样式,那将是一个胜利:

$(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>

var wscols = [{wpx: 100}];
ws['!cols'] = wscols ;

您正在使用 SheetJS 库的社区版本,并且此版本 无法 进行样式设置。但是 Pro Version 样式功能可用。

查看此官方评论:

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

有关专业版的更多信息,请访问其官方网站:http://sheetjs.com/pro