question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to set Header in a different row?

See original GitHub issue

Is there a way to set the headers on a diferent row, other than the first?

I’m trying to do this

`var Excel = require('exceljs');
    var workbook = new Excel.Workbook();
    var headers = [
      {header:'Cliente',key:'client_name'  ,width: 18}, // i need something like headerRow: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.properties.defaultRowHeight = 15;
        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)
          .then(function() {
            callback(null,output);
          });`

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:9
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
abyss-kpcommented, Aug 14, 2020

I wanted my headers to start from 3rd row and 1st-row 1st cell had some metadata,so what I did was:

  1. Duplicated my headers in 3 rows (1,2,3). worksheet.duplicateRow(1, 2, true); //duplicate header row 2 times with values and style; in row2 and row3

  2. Added metadata in 1st row worksheet.getRow(1).values = ['Some meta data'] //Replace row1 headers with "Berry Type";here we pass an array where each index denotes a cells

  3. Removing duplicated headers from 2nd row worksheet.getRow(2).values = [] //Delete row2 duplicated above in step 1

And here’s my output:

Metadata |   |   |   |   – | – | – | – | –   |   |   |   |   header1 | Header2 | header3 | header4 | header5 1 | 2 | 3 | 4 | 5

2reactions
sevenstoriescommented, Mar 6, 2019

I’ve managed to offset the header row by using splice rows set to remove 0 rows and giving it an empty array of the desired amount of rows, just place it after all rows have been added. A similar technique could be applied to columns. Anything you want to add above the header rows will need to be set directly (not using addRow or addRows, so presumably wont work for a streamed file if the rows are already committed?) Or you could specify it in the array parameter of splice in place of the new Array(offset) parameter

let offset = 3; // to offset by 3 rows
worksheet.spliceRows(1,0,new Array(offset))
Read more comments on GitHub >

github_iconTop Results From Across the Web

Set up your header row - Microsoft Support
In the query pane, select Edit to open the Power Query editor. · To confirm that Power Query recognized your headers in the...
Read more >
How To Create a Header Row in Excel Using 3 Methods
How to create a header row in Excel by printing · 1. Open Excel and the correct spreadsheet · 2. Find "Page Layout"...
Read more >
The Simplest Way to Add a Header Row in Excel - wikiHow
1. Click the View tab. If you want to keep a row of data visible at all times, even when you've scrolled down...
Read more >
How to make an Excel header row - Excelchat - Got It AI
Add print title · Click Page Layout tab > Print Titles · In the Page Setup dialog box, Sheet tab, enter row 2...
Read more >
Changing the Table Header Row - Spreadsheet.com Support
To change the table header row, select the new row you would like to set as the table header, right-click on the row...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found