Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExcelJS node: horizontalCentered & verticalCentered in page not working

plz help me.

My flow:

Using a file Tempate -> Code (Exceljs) -> output New file

Template file:

enter image description here Center on page:

  • horizontally : Checked
  • vertically : Checked

Source coder:

worksheet.pageSetup.horizontalCentered = true 
worksheet.pageSetup.verticalCentered = true

BUT File output:

  • horizontal : uncheck
  • vertical : uncheck
like image 334
Tính Ngô Quang Avatar asked Dec 09 '19 08:12

Tính Ngô Quang


People also ask

What is ExcelJS?

ExcelJS is a JavaScript library for reading, manipulating and writing spreadsheet data in XLSX format.

Is ExcelJS free?

In addition, exceljs is frequently updated from time to time and available for free.

How do you set Excelsheet row height to auto so that the content can AutoFit in the cell using ExcelJS?

On the Format button's menu, select AutoFit Column Width and notice that the width of Column A has changed to contain the length of the text in the A1 cell. Unlike column widths, Excel automatically adjusts the height of a row to accommodate the height of the text that takes up the most vertical space in each row.


2 Answers

Please tell me if this worked well or not.

// DO NOT SET ANOTHER pageSetup AFTER DECLARING THIS!

var worksheet =  workbook.addWorksheet('sheet', {
  pageSetup: {
    horizontalCentered: true,
    verticalCentered: true,
    paperSize: 9,
    orientation: 'portrait',
    margins: {
      left: 0.3149606, right: 0.3149606,
      top: 0.3543307, bottom: 0.3543307,
      header: 0.3149606, footer: 0.3149606
    }
  }
})

like image 163
Edi Imanto Avatar answered Sep 28 '22 06:09

Edi Imanto


Please check below link and code.

https://github.com/Great-hijack/react-excel/blob/master/frontend/src/utils/export2excel.js

var sheet1 = workbook.addWorksheet('Download', { properties: { tabColor: { argb: '6B5B95' }, defaultRowHeight: 39 } });
// Page Setup for sheet1
sheet1.pageSetup.paperSize = 13; // B5 (JIS)
sheet1.pageSetup.orientation = 'landscape';
sheet1.pageSetup.horizontalCentered = true;
sheet1.pageSetup.verticalCentered = true;
sheet1.pageSetup.margins = {
    left: 0.7, right: 0.7,
    top: 0.3, bottom: 0.3,
    header: 0.3, footer: 0.3
};

I hope this is helpful for you.

like image 42
Zhen Avatar answered Sep 28 '22 05:09

Zhen