Skip to content
ExcelJS실무 경험

Fitting the Width to the Content in ExcelJS

1 min readWorkMoved from my Tistory blogRead the Korean original

After I finished drawing the Excel file, it came out larger than A4, so every time I printed it I had to set the width to 1 page in Page Layout, which was a hassle.

I looked for a way to fix this. Going through worksheet.pageSetup.pageSize only let me switch between the predefined sizes, so I looked for another way, and it is the code below.

js
  const workbook = new ExcelJS.Workbook();
  const worksheet = workbook.addWorksheet('Sheet');
  worksheet.pageSetup.fitToPage = true; // Fit the width to the content
  worksheet.pageSetup.fitToHeight = 0; // Set the height automatically
  • #ExcelJS
  • #page width
  • #fit to page

More in Work