javascript - ExcelJS freeze rows - Stack Overflow

I'm trying to freeze rows in ExcelJS but cannot get it to work.I'm trying bothworksheet.views

I'm trying to freeze rows in ExcelJS but cannot get it to work.

I'm trying both

worksheet.views = [
{state: 'frozen', ySplit: 1}
];

and

workbook.addWorksheet(sheetName, {
views: [
{state: 'frozen', ySplit: 1}
]
});

but it doesn't work.

I also get the "We found a problem with...Do you want to recover as much.." warning when opening up the spreadsheet.

Anyone getting this to work? All I want to do is freeze the 7th row. I can do this in Excel itself

There's an Issue reported here that seems to say it's just not a feature in Excel itself. But I'm wondering why it corrupts the file too.

I'm trying to freeze rows in ExcelJS but cannot get it to work.

I'm trying both

worksheet.views = [
{state: 'frozen', ySplit: 1}
];

and

workbook.addWorksheet(sheetName, {
views: [
{state: 'frozen', ySplit: 1}
]
});

but it doesn't work.

I also get the "We found a problem with...Do you want to recover as much.." warning when opening up the spreadsheet.

Anyone getting this to work? All I want to do is freeze the 7th row. I can do this in Excel itself

There's an Issue reported here that seems to say it's just not a feature in Excel itself. But I'm wondering why it corrupts the file too.

Share Improve this question asked Apr 6, 2020 at 17:41 user2402616user2402616 1,5734 gold badges23 silver badges55 bronze badges 2
  • 1 Just double-checking that you're using Node.js and the exceljs package...? I mistakenly read the question at first as being about Excel's own JavaScript API, but you used the excejs tag and I see that views is something that the package talks about, so... – T.J. Crowder Commented Apr 6, 2020 at 17:48
  • 1 Correct, I'm using excelJS package and not Excel's JS API (didn't even know there was an official one..?) – user2402616 Commented Apr 6, 2020 at 18:43
Add a ment  | 

1 Answer 1

Reset to default 4

Try this:

workbook.addWorksheet(sheetName, {
    views: [{ state: "frozen", ySplit: 1 }],
});

It's working for me.

More details:

const Excel = require("exceljs");

const writeFile = async (sheetName, columns, list, file) => {
  let workbook = new Excel.Workbook();
  let sheet = workbook.addWorksheet(sheetName, {
    views: [{ state: "frozen", ySplit: 1 }],
  });
  sheet.columns = columns;

  for (const record of list) {
    sheet.addRow(record);
  }
  workbook.xlsx.writeFile(file);
};


const test = async () => {
  const columns = [
    { header: "Column1", key: "column1" },
    { header: "Column2", key: "column2" },
    { header: "Column3", key: "column3" },
  ];
  let list = [];
  for (let i = 1; i < 100; i++) {
    let record = {};
    record.column1 = `line${i}_column1`;
    record.column2 = `line${i}_column2`;
    record.column3 = `line${i}_column3`;
    list.push(record);
  }
  const file = "c:/temp/test.xlsx";
  await writeFile("sheet1", columns, list, file);
};
test();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745323076a4622530.html

相关推荐

  • javascript - ExcelJS freeze rows - Stack Overflow

    I'm trying to freeze rows in ExcelJS but cannot get it to work.I'm trying bothworksheet.views

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信