Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

768
Views
How to set excelsheet row height to auto so that the content can autofit in the cell using exceljs

I am using exceljs npm to export data in excelsheet. As my content in the cell is huge so I wanted text to be wrapped in the cell and should take enough height to show full content. I tried by giving fixed width -

worksheet.getRow(1).height = 20;

The problem with fixed height is that if my content is large than this size then it won't fit in the cell and it shows cropped text like shown in the screenshot.

enter image description here

I wanted cells to look like this enter image description here

I have gone through the exceljs documentation but didn't find anything.

Thanks in advance !!

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Have you already tried not to define the height of the row? I had the same problem and I solved it like this and that way the height of the row adjusts automatically.

I hope the solution I applied in my case is useful to you. Greetings.

over 4 years ago · Santiago Trujillo Report

0

what worked for me was ,

worksheet.addRow(temp);
const row = worksheet.lastRow;
row.getCell(3).alignment = { wrapText: true };

when ever a new row is added, that rows 3rd cell alignment has to be set.

or

once all the rows are added in that sheet , iterated over all the rows and set the alignment property.

over 4 years ago · Santiago Trujillo Report

0

You can do something like this: Foreach on your data and get the desired row through the index

const row = worksheet.getRow(index);
    row.height = row.height * 20 / row.width;

*NOTE:

  • I fixed the number '20', but you can also make it a variable

  • In my excel, my data data starts at line four onwards, so I do:

     const row = worksheet.getRow(index + 4);
    
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!