0

This is my code. It creates a xlsx file which is opening in libreoffice but shows corrupt in excel-2007

also workbook.xlsx.write(response) downloads .zip file

Please help.

var Excel = require("exceljs");
var express = require("express");
var bodyParser = require("body-parser");

var app = express();

app.use(bodyParser.urlencoded({ extended: false }));

app.use(bodyParser.json());

app.all("/getExcel", function(req, res) {

var workbook = new Excel.Workbook();
var worksheet = workbook.addWorksheet("Discography");

worksheet.columns = [{ header: "Album", key: "album" }, { header: "Year", key: "year" }];

worksheet.addRow({ album: "Taylor Swift", year: 2006 });

worksheet.addRow(["Fearless", 2008]);

var rows = [["Speak Now", 2010], { album: "Red", year: 2012 }];
worksheet.addRows(rows);

worksheet.getCell("A6").value = "1989";
worksheet.getCell("B6").value = 2014;

workbook.xlsx.writeFile('taylor_swift.xlsx').then(fenter code hereunction() {
console.log("saved");
});
});
  • save it from libreoffice and if excel accept this input then compare the two files in a hex-editor – split Aug 23 '18 at 15:34

2 Answers2

0

Try to create template file in MSO and then open it with exceljs. As for me, this trick usually works fine.

0

I also have problems like you. Using a template XLSX file-> fill content with exceljs nodejs -> convert to PDF file with libreOffice. But it cannot display all sheets.

exceljs: Add new sheet then default is { state: 'hidden' }

I have found the cause:

var sheet2 = workbook.addWorksheet('S2',{state: 'visible'});
Tính Ngô Quang
  • 4,400
  • 1
  • 33
  • 33