Excel file needs to be repaired after saving #3092

Closed
opened 2024-03-25 09:11:10 +00:00 by felix0110 · 2 comments

I have my project running xlsx with this issues. The biggest and most problematic of these is the fact that whenever I save my workbook and then attempt to open it. I get this problem:
image

   var workbook = XLSX.readFile(
            `./templates/test.xlsx`,
            {
              cellHTML: true,
              cellStyles: true,
              cellDates: true,
              cellNF: false,
              cellText: false,
            }
          );
          var sheetNames = workbook.SheetNames;

          workbook.SheetNames.forEach(function (sheetName) {
            var worksheet = workbook.Sheets[sheetName];

            for (var i = 1; i <= 100; i++) {
              var border = {
                top: { style: "thin", color: "FF000000" },
                right: { style: "thin", color: "FF000000" },
                bottom: { style: "thin", color: "FF000000" },
                left: { style: "thin", color: "FF000000" },
              };
              var fill = {
                patternType: "solid", // none / solid
                fgColor: { rgb: "FFC0C0C0" },
                // bgColor: {rgb: "FFC0C0C0"}
              };
              worksheet[XLSX.utils.encode_cell({ r: i, c: 0 })] = {
                v: result["HospitalID"],
                s: { border: border, fill: fill },
              };
              worksheet[XLSX.utils.encode_cell({ r: i, c: 2 })] = {
                v: result["Code"],
                s: { border: border, fill: fill },
              };
              worksheet[XLSX.utils.encode_cell({ r: i, c: 1 })] = {
                v: result["Name"],
                s: { border: border, fill: fill },
              };
            }

            result[sheetName] = XLSX.utils.sheet_to_json(worksheet);
          });

          var wopts = { bookType: "xlsx", type: "buffer" };
          var wbout = XLSX.write(workbook, wopts);
          res.setHeader(
            "Content-disposition",
            "attachment; filename=" +
              `test.xlsx`
          );
          res.setHeader(
            "Content-type",
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
          );
          res.charset = "UTF-8";
          res.write(wbout, "binary");
          res.end(null, "binary");
I have my project running xlsx with this issues. The biggest and most problematic of these is the fact that whenever I save my workbook and then attempt to open it. I get this problem: ![image](/attachments/b5fae212-7cce-41f0-8ac1-a41686dbb7c0) ``` var workbook = XLSX.readFile( `./templates/test.xlsx`, { cellHTML: true, cellStyles: true, cellDates: true, cellNF: false, cellText: false, } ); var sheetNames = workbook.SheetNames; workbook.SheetNames.forEach(function (sheetName) { var worksheet = workbook.Sheets[sheetName]; for (var i = 1; i <= 100; i++) { var border = { top: { style: "thin", color: "FF000000" }, right: { style: "thin", color: "FF000000" }, bottom: { style: "thin", color: "FF000000" }, left: { style: "thin", color: "FF000000" }, }; var fill = { patternType: "solid", // none / solid fgColor: { rgb: "FFC0C0C0" }, // bgColor: {rgb: "FFC0C0C0"} }; worksheet[XLSX.utils.encode_cell({ r: i, c: 0 })] = { v: result["HospitalID"], s: { border: border, fill: fill }, }; worksheet[XLSX.utils.encode_cell({ r: i, c: 2 })] = { v: result["Code"], s: { border: border, fill: fill }, }; worksheet[XLSX.utils.encode_cell({ r: i, c: 1 })] = { v: result["Name"], s: { border: border, fill: fill }, }; } result[sheetName] = XLSX.utils.sheet_to_json(worksheet); }); var wopts = { bookType: "xlsx", type: "buffer" }; var wbout = XLSX.write(workbook, wopts); res.setHeader( "Content-disposition", "attachment; filename=" + `test.xlsx` ); res.setHeader( "Content-type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ); res.charset = "UTF-8"; res.write(wbout, "binary"); res.end(null, "binary"); ```
Owner

https://docs.sheetjs.com/docs/demos/net/server/express you should only need:

var wbout = XLSX.write(workbook, wopts);
res.attachment("test.xlsx");
res.status(200).end(wbout); 

Please confirm you are using the latest version of the library. Review the installation notes https://docs.sheetjs.com/docs/getting-started/installation/nodejs . If this issue still affects the latest version, please share the generated file and we can reopen the issue.

https://docs.sheetjs.com/docs/demos/net/server/express you should only need: ```js var wbout = XLSX.write(workbook, wopts); res.attachment("test.xlsx"); res.status(200).end(wbout); ``` Please confirm you are using the latest version of the library. Review the installation notes https://docs.sheetjs.com/docs/getting-started/installation/nodejs . If this issue still affects the latest version, please share the generated file and we can reopen the issue.
Author

https://docs.sheetjs.com/docs/demos/net/server/express you should only need:

var wbout = XLSX.write(workbook, wopts);
res.attachment("test.xlsx");
res.status(200).end(wbout); 

Please confirm you are using the latest version of the library. Review the installation notes https://docs.sheetjs.com/docs/getting-started/installation/nodejs . If this issue still affects the latest version, please share the generated file and we can reopen the issue.

The version is the latest version 0.18.5.

Even i change as follow, the same error occurs.

var wbout = XLSX.write(workbook, wopts);
res.attachment("test.xlsx");
res.status(200).end(wbout); 
> https://docs.sheetjs.com/docs/demos/net/server/express you should only need: > > ```js > var wbout = XLSX.write(workbook, wopts); > res.attachment("test.xlsx"); > res.status(200).end(wbout); > ``` > > Please confirm you are using the latest version of the library. Review the installation notes https://docs.sheetjs.com/docs/getting-started/installation/nodejs . If this issue still affects the latest version, please share the generated file and we can reopen the issue. The version is the latest version 0.18.5. Even i change as follow, the same error occurs. ``` var wbout = XLSX.write(workbook, wopts); res.attachment("test.xlsx"); res.status(200).end(wbout); ```
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#3092
No description provided.