admin管理员组

文章数量:1287993

plz help me.

My flow:

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

Template file:

Center on page:

  • horizontally : Checked
  • vertically : Checked

Source coder:

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

BUT File output:

  • horizontal : uncheck
  • vertical : uncheck

plz help me.

My flow:

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

Template file:

Center on page:

  • horizontally : Checked
  • vertically : Checked

Source coder:

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

BUT File output:

  • horizontal : uncheck
  • vertical : uncheck
Share Improve this question edited Dec 9, 2019 at 9:06 Tính Ngô Quang asked Dec 9, 2019 at 8:59 Tính Ngô QuangTính Ngô Quang 4,6521 gold badge37 silver badges34 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

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
    }
  }
})

Please check below link and code.

https://github./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.

Can you show the code, So that it will be easy to figure the problem.

But, While creating worksheet have you specified,

useStyles: true

var workbook = new Excel.stream.xlsx.WorkbookWriter({
    filename: filename.xlsx,
    useStyles: true
});

See below code, If it could be of any help -

var worksheet = workbook.addWorksheet(date);
    worksheet.columns = [{
            header: 'Col-1',
            key: 'col_1',
            width: 5
        },
       {
            header: 'Col-2',
            key: 'col_2',
            width: 5
        },
    ];

    for (let i in data) {
        worksheet.addRow(data[i]);
    }

    // set style for each cell
    worksheet.eachRow(function (Row, rowNum) {

        Row.eachCell(function (Cell, cellNum) {

            if (rowNum == 1) {
                Cell.alignment = {
                    vertical: 'center',
                    horizontal: 'center'
                }
            }else{
                Cell.alignment = {
                    vertical: 'middle',
                    horizontal: 'middle'
                }
            }
        })
    })

    workbook.mit()
        .then(function () {
            console.log('Excel export plete!');
            process.exit()
        });

本文标签: javascriptExcelJS node horizontalCentered amp verticalCentered in page not workingStack Overflow