exceljs / exceljs

Excel Workbook Manager
MIT License
13.72k stars 1.75k forks source link

Downloaded xlsx file is opening in libreOffice but shows corrupt in excel 2007 #631

Open abhinavankur3 opened 6 years ago

abhinavankur3 commented 6 years ago

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(function() { console.log("saved"); }); });

abhijitborade commented 6 years ago

I am also facing the same issue.

xurei commented 6 years ago

Same issue for me. Here is the fully-generated file. report(1).xlsx

For information :

I'm using the latest version of exceljs (1.6.2)

Here is a dirty copy/paste of the code : https://gist.github.com/xurei/03aa1d73b7f4b483cdc0b3e0038e3081

raamkumaarb commented 6 years ago

I am also facing the same issue in Excel 2007. Anyone find a fix for this?

Yuiffy commented 6 years ago

same issue. One User use Excel 2016, say it is corrupt; but my Excel 2016 can open the same excel. strange

Mafi78 commented 6 years ago

Hi, Is it possible that there is an issue with fonts on one computer installed and on the other not ? I noticed that on my machine i got errors related to that. It was not in that context, but that could explain the behavior ?

Am 25.10.2018 um 13:16 schrieb Yuiffy notifications@github.com:

same issue. One User use Excel 2016, say it is corrupt; but my Excel 2016 can open the same excel. strange

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/guyonroche/exceljs/issues/631#issuecomment-433011612, or mute the thread https://github.com/notifications/unsubscribe-auth/ACLYMXP2jV5kIKM1EBNLYCzsiwihbROmks5uoZ19gaJpZM4WJnQO.

YassienW commented 5 years ago

Same issue here on Excel 2007, quite annoying since saving files is a critical function. Opens perfectly fine with LibreOffice as well (6.1.2.1), first sheet only is shown just like @xurei

https://gist.github.com/YassienW/936a1c4bd9114d483808080af0f08199

edit: Saving as from LibreOffice seems to fix the file for excel edit2: Totally empty xlsx files have the same issue as well

abhijitborade commented 5 years ago

You will need to create your template file in Microsoft Excel or Google Sheets that too from scratch and make sure you do not copy over anything from the old file that you created in Libre. You can copy the contents but you should do paste as plain text.

YassienW commented 5 years ago

I'm pretty sure it was originally created via Microsoft Excel. Right now i switched to using another library for saving files since this was sadly too inconvenient

tinhnqjp commented 5 years ago

Maybe you are like my cause.

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.

https://stackoverflow.com/a/54286302/3085133

a5006 commented 4 years ago

Same issue for me. Here is the fully-generated file. report(1).xlsx

For information :

  • It does open in Zoho Sheet and Excel 2016 (for Mac) without any problem,
  • It does open on LibreOffice 5.4.5.1, but the first sheet only is shown, the other is not,
  • Excel 2007 refuses to open and complains about a corrupt file. I tried to generate only one sheet of each, refuses as well.

I'm using the latest version of exceljs (1.6.2)

Here is a dirty copy/paste of the code : https://gist.github.com/xurei/03aa1d73b7f4b483cdc0b3e0038e3081

hi, the link was expired, can you show me the code ? I am facing this problem ,thx

xurei commented 4 years ago

@a5006 I just made the gist public. You should have access now.

prabushitha commented 4 years ago

Maybe this could not related to the given code fragment's issue, but I had the same issue where libre shows correctly but excel mark it as a corrupted file. With some analysis of my code I found that using pageSetup and margins caused the issue. My code was like below

pageSetup: { 
  margins: {
        left: 0.1,
        right: 0.1,
  }
}

exceljs this section of code https://github.com/exceljs/exceljs/blob/master/lib/doc/worksheet.js#L67 Uses Object.assign but margin is also another javascript object where it would just remove the other margin defaults. (but Microsoft Excel needs all the margin attributes defined it seems) As a solution, I had to define all the margin attributes like below.

pageSetup: { 
  margins: {
        left: 0.1,
        right: 0.1,
        top: 1,
        bottom: 1,
        header: 1,
        footer: 1,
  }
}

Hope this would help someone!