exceljs如何在不同的行中设置标题

时间:2017-03-03 16:24:19

标签: node.js exceljs

您好我正在使用exceljs库获取节点,我正在读取一个文件,用作我们的Excel的模板,我想使用addrows函数和列的标题属性,但我没看到文档如何将标题放在与第一行不同的另一行上。

我这样做。

var headers = [
  {header:'Cliente',key:'client_name'  ,width: 18}, //i need something like startRow:2
  {header:'N° Visitas',key:'visits'  ,width: 10},
  {header:'Visitas Periodo Anterior',key:'visits_old'  ,width: 10},
  {header:'Ultima visita',key:'last_visit',style: { numFmt: 'DD/MM/YYYY HH:mm:ss' },width: 22},
  {header:'Ultima Persona en Visitarlo',key:'device_name'  ,width: 18}
];

var libro  = workbook.xlsx.readFile(template_file)
  .then(function() {
    var worksheet = workbook.getWorksheet(1);

    worksheet.columns = headers;
    worksheet.addRows(data);

    //row.height=40;
    worksheet.getRow(1).hidden=false;
    worksheet.getRow(2).hidden=false;

    //row.height=40;
    workbook.xlsx.writeFile(output)

注意:抱歉,如果我拼错了。

1 个答案:

答案 0 :(得分:1)

var dobCol = worksheet.getRow(1); // You can define a row like 2 , 3

dobCol.header = [{
{header:'Cliente',key:'client_name'  ,width: 18}, //i need something like startRow:2
  {header:'N° Visitas',key:'visits'  ,width: 10},
  {header:'Visitas Periodo Anterior',key:'visits_old'  ,width: 10},
  {header:'Ultima visita',key:'last_visit',style: { numFmt: 'DD/MM/YYYY HH:mm:ss' },width: 22},
  {header:'Ultima Persona en Visitarlo',key:'device_name'  ,width: 18}
}];