首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何使用excelJs设置导出文件头的样式

如何使用excelJs设置导出文件头的样式
EN

Stack Overflow用户
提问于 2019-09-26 15:21:02
回答 1查看 10K关注 0票数 4

如何在excelJs中自定义创建页眉的边框、颜色、宽度等样式?

我可以设置工作表的行的样式,但不能设置页眉的样式

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  fDay = days[0].charAt(0)
  sDay = days[1].charAt(0)
  sheet.columns = [
    {header: 'Num', key: 'id'},
    {header: 'Nom prenom', key: 'name'},
    {header: 'Date de naissance', key: 'birthday'},
    {header: fDay+'1', key: fDay+'1', style: {border: 'thin'}},
    {header: sDay+'1', key: sDay+'1'},
    {header: fDay+'2', key: fDay+'2'},
    {header: sDay+'2', key: sDay+'2'},
    {header: fDay+'3', key: fDay+'3'},
    {header: sDay+'3', key: sDay+'3'},
    {header: fDay+'4', key: fDay+'4'},
    {header: sDay+'4', key: sDay+'4'},
    {header: fDay+'5', key: fDay+'5'},
    {header: sDay+'5', key: sDay+'5'},
  ]
  $.each(dataPlayers, (index, player)=>{
    row = sheet.addRow({id: player.id, name: player.Prenom+' '+player.Nom, birthday: getShortDate(player.DateNaissance)})
    row.eachCell(function(cell) {
         cell.border = {
           top: {style:'thin'},
           left: {style:'thin'},
           bottom: {style:'thin'},
           right: {style:'thin'}
         };
       })
  })

结果是这样的

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-01 12:23:02

因此,我发现的方法是创建所有行,然后迭代每行的每个单元格,以在其上或其自身的行上应用样式:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
sheet.eachRow({ includeEmpty: true }, function(row, rowNumber){
  row.eachCell(function(cell, colNumber){
   cell.font = {
     name: 'Arial',
     family: 2,
     bold: false,
     size: 10,
   };
   cell.alignment = {
     vertical: 'middle', horizontal: 'center'
   };
   if (rowNumber <= 10) {
     row.height = 20;
     cell.font = {
       bold: true,
     };
    }
    if (rowNumber >= 10) {
     for (var i = 1; i < 14; i++) {
       if (rowNumber == 10) {
         row.getCell(i).fill = {
           type: 'pattern',
           pattern:'solid',
           fgColor:{argb:'C7C7C7'}
         };
       }
       row.getCell(i).border = {
       top: {style:'thin'},
       left: {style:'thin'},
       bottom: {style:'thin'},
       right: {style:'thin'}
     };
   }
  }
 });
});

使用documentation of excelJS来使用样式属性

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58120009

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文