We found a problem with some content in the "fileName". #1537

Closed
opened 2019-06-14 11:10:00 +00:00 by akspan12 · 3 comments
akspan12 commented 2019-06-14 11:10:00 +00:00 (Migrated from github.com)

I am using this function to extract column names from JSON data and write it to an excel file. I am getting "We found a problem with some content in the "fileName". Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes". I checked all possible solutions but nothing is working.

async _generateExcel(jsonData) {
        let wb = XLSX.utils.book_new();
        wb.Props = {
            Title: "Test migration",
            Subject: "Test",
            Author: "Akshansh"
        };
        wb.SheetNames.push("Sheet1");
        let ws_data = [];
        let writeData = [];
        jsonData.worksheet.columnData.forEach(column => {
            writeData.push(column.name);
        });
        ws_data.push(writeData);
        console.log(ws_data);
        let ws = XLSX.utils.aoa_to_sheet(ws_data);
        wb.Sheets["Sheet1"] = ws;
        let filePath = FE.APP_PATH + `/excel-file`;
        await XLSX.writeFile(wb, filePath+`/${jsonData.fileCode}.xlsx`);
    }
I am using this function to extract column names from JSON data and write it to an excel file. I am getting "We found a problem with some content in the "fileName". Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes". I checked all possible solutions but nothing is working. ``` async _generateExcel(jsonData) { let wb = XLSX.utils.book_new(); wb.Props = { Title: "Test migration", Subject: "Test", Author: "Akshansh" }; wb.SheetNames.push("Sheet1"); let ws_data = []; let writeData = []; jsonData.worksheet.columnData.forEach(column => { writeData.push(column.name); }); ws_data.push(writeData); console.log(ws_data); let ws = XLSX.utils.aoa_to_sheet(ws_data); wb.Sheets["Sheet1"] = ws; let filePath = FE.APP_PATH + `/excel-file`; await XLSX.writeFile(wb, filePath+`/${jsonData.fileCode}.xlsx`); } ```
SheetJSDev commented 2019-07-29 09:58:29 +00:00 (Migrated from github.com)

Can you share the generated file?

Can you share the generated file?
scottyh527 commented 2019-10-25 21:00:47 +00:00 (Migrated from github.com)

Hi I am having the same issuee as well. The xlsx file seems to be ok upon opening it but I'd like to prevent the alert from happening. I am trying to execute this on the client side so that usere can download the data.

  exportToXlsx: ( title, rows )=>{
    var wb = XLSX.utils.book_new();
    wb.Props = {
      Title: title,
      Subject: "Test",
      Author: "",
      CreatedDate: new Date()
    };
    wb.SheetNames.push('Test Sheet');
    var ws_data = rows;
    var ws = XLSX.utils.aoa_to_sheet(ws_data);
    wb.Sheets["Test Sheet"] = ws;

    var wbout = XLSX.write(wb, { bookType:'xlsx', type: 'binary'});
    function s2ab(s) {
      var buf = new ArrayBuffer(s.length); //convert s to arrayBuffer
      var view = new Uint8Array(buf);  //create uint8array as viewer
      for (var i = 0; i < s.length; i++) view[i] = s.charCodeAt(i) & 0xFF; //convert to octet
      return buf;
    }
    
    let blob = new Blob([s2ab(wbout)], {type: 'application/octet-stream'});
    if (navigator.msSaveBlob) { // IE 10+
      navigator.msSaveBlob(blob, title);
    } else {
      let link = document.createElement("a");
      if (link.download !== undefined) { // feature detection
        // Browsers that support HTML5 download attribute
        let url = URL.createObjectURL(blob);
        link.setAttribute("href", url);
        link.setAttribute("download", title);
        link.style.visibility = 'hidden';
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
      }
    }

  },
Hi I am having the same issuee as well. The xlsx file seems to be ok upon opening it but I'd like to prevent the alert from happening. I am trying to execute this on the client side so that usere can download the data. ``` exportToXlsx: ( title, rows )=>{ var wb = XLSX.utils.book_new(); wb.Props = { Title: title, Subject: "Test", Author: "", CreatedDate: new Date() }; wb.SheetNames.push('Test Sheet'); var ws_data = rows; var ws = XLSX.utils.aoa_to_sheet(ws_data); wb.Sheets["Test Sheet"] = ws; var wbout = XLSX.write(wb, { bookType:'xlsx', type: 'binary'}); function s2ab(s) { var buf = new ArrayBuffer(s.length); //convert s to arrayBuffer var view = new Uint8Array(buf); //create uint8array as viewer for (var i = 0; i < s.length; i++) view[i] = s.charCodeAt(i) & 0xFF; //convert to octet return buf; } let blob = new Blob([s2ab(wbout)], {type: 'application/octet-stream'}); if (navigator.msSaveBlob) { // IE 10+ navigator.msSaveBlob(blob, title); } else { let link = document.createElement("a"); if (link.download !== undefined) { // feature detection // Browsers that support HTML5 download attribute let url = URL.createObjectURL(blob); link.setAttribute("href", url); link.setAttribute("download", title); link.style.visibility = 'hidden'; document.body.appendChild(link); link.click(); document.body.removeChild(link); } } }, ```
SheetJSDev commented 2019-10-25 22:59:32 +00:00 (Migrated from github.com)

Thanks for your patience and feedback @scottyh527 ! He was kind enough to share a repro.

Excel has a limit of 32767 characters in a cell.

@akspan12 can you check if any cell you are writing is actually too long?

@scottyh527 we'll accept a PR that errors if a string length exceeds 32768 characters. The check should appear before the opts.bookSST check in https://github.com/SheetJS/js-xlsx/blob/master/bits/67_wsxml.js#L260

		default: if(cell.v == null) { delete cell.t; break; }
+			if(cell.v.length > 32767) throw new Error("Text length must not exceed 32767 characters");
			if(opts.bookSST) {
Thanks for your patience and feedback @scottyh527 ! He was kind enough to share a repro. [Excel has a limit of 32767 characters in a cell](https://support.office.com/en-us/article/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3). @akspan12 can you check if any cell you are writing is actually too long? @scottyh527 we'll accept a PR that errors if a string length exceeds 32768 characters. The check should appear before the `opts.bookSST` check in https://github.com/SheetJS/js-xlsx/blob/master/bits/67_wsxml.js#L260 ```diff default: if(cell.v == null) { delete cell.t; break; } + if(cell.v.length > 32767) throw new Error("Text length must not exceed 32767 characters"); if(opts.bookSST) { ```
Sign in to join this conversation.
No Milestone
No Assignees
1 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#1537
No description provided.