xlsx-populate icon indicating copy to clipboard operation
xlsx-populate copied to clipboard

Excel Corrupted after simple import export

Open lmX2015 opened this issue 3 years ago • 3 comments

Hi there!

I am experiencing an odd bug when importing a specific excel file. Parsing function is doing great, I can access normally the excel content and style, however exporting it back creates a corrupted file where all the text has been removed (by the Excel "repair tool"). I am attaching the file test_style.xlsx I though this was due to an unsupported style, however even non styled text is removed. Any idea what can cause this issue?

Here is a snippet to test it:

const XlsxPopulate = require('xlsx-populate');
XlsxPopulate.fromFileAsync("./test_style.xlsx")
    .then(workbook => {
        // Write to file.
        return workbook.toFileAsync("./out.xlsx");
    });

I tried the following version of xlsx-populate:

  • 1.21.0
  • 1.18.0 (I saw another issue quite similar caused by the 1.19 version but it didn't work either on this one)

Node version 13.7.0.

Thanks a lot in advance!

lmX2015 avatar Mar 02 '21 10:03 lmX2015

same issue for me - no response?

Frodo1980 avatar Apr 22 '22 13:04 Frodo1980

same problem

andriat-jubelio avatar Jan 12 '23 10:01 andriat-jubelio

I could solve my problem by using this (serverless function in my usecase)

`router.get("/", (req, res) => { // Load an existing workbook

XlsxPopulate.fromFileAsync("ExcelBlanko.xlsx") .then((workbook) => { const sheet1 = workbook.sheet("sheet1");

  const params = req.query;

  //transfer req-parameters in cells (watch the data-types!!!)

  // Arbeitsblatt anpassen
  Object.keys(params).map((key, index) => {
    // der Parameter "key" dient nur als Voraussetzung zum Ausführen der Funktion
    if (key != "key") {
      // Alle auf dem Tabellenblatt "sheet1" zu ändernden Zellen befinden sich in Spalte "D"
      if (key.charAt(0) === "D") {
        kalkulationstool.cell(key).value(Object.values(params)[index]);
      }
      // Alle auf dem Tabellenblatt "Wertbeitrag" zu ändernden Zellen befinden sich in Spalte "C"
      if (key.charAt(0) === "C") {
        wertbeitrag.cell(key).value(Object.values(params)[index]);
      }
      // Alle auf dem Tabellenblatt "Bewertung Aufstockung" zu ändernden Zellen befinden sich in Spalte "B"
      if (key.charAt(0) === "B") {
        wertbeitrag.cell(key).value(Object.values(params)[index]);
      }
    }
  });

  **return workbook.outputAsync("base64");**
})
.then((data) => {
  // Send the workbook as base64-string
  res.send(data);
});

});`

The file which sends the request handles the response like this (sorry for this vue-style - hope you can adopt it to your needs):

<a id="link" download="file.xlsx" :href="url" v-if="showExcel" style="color: blue" > Download </a>

and

` var vm = this;

  //Übergabe der Eingabewerte an netlify-function
  let url =
    "YOUR LINK TO SERVERLESS FUNCTION";
  axios
    .get(url, {
      params: {
        D7: [VALUE FOR CELL D7],
      },
    })
    .then(function (response) {
      vm.url =
        **"data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64," +
        response.data;**

      //Show Download
      vm.showExcel = true;
    })
    .catch(function (error) {
      console.log(error);
    })
    });`

Hope it helps. Base64 was the magic in my usecase

Frodo1980 avatar Jan 12 '23 17:01 Frodo1980