protobi / js-xlsx

XLSX / XLSM / XLSB (Excel 2007+ Spreadsheet) / ODS parser and writer
http://oss.sheetjs.com/js-xlsx
Other
817 stars 417 forks source link

Issue with Multiline in cell even after setting the wrapText Property #58

Open selvishah opened 7 years ago

selvishah commented 7 years ago

Hi, I am seeing an issue where even after setting the wrapText property and setting the write attribute with bookSST : true, the cell does not display the text in multiline until I explicitly double click on the cell.

Is there a way for it to display correctly without any manual edits?

function writeExcel(workSheet,cell,data){ workSheet[cell] = {v:"Test Case Steps", t:'s', }; workSheet[cell].s = {alignment:{wrapText: true}}; cellColumnStart = cell.split('',1)[0]; cellRowStart = parseInt(cell.replace(/[A-Z]/,"")); var dataString;

  data.forEach(function (row){
    cellRowStart += 1;
    cellRef = cellColumnStart+cellRowStart;
    dataString = "";
    row = row[0];
    cellCurrent = {v:dataString,
                   t:'s',
                  };
    row.forEach(function (scenario){
         datastring += scenario+"\n"; # this should be display as multiline in each cell
      })
    cellCurrent.v = "\"" + dataString  + "\"";
    workSheet[cellRef] = cellCurrent;
    workSheet[cellRef].s = {alignment:{wrapText: true}};
  })
  var range = workSheet['!ref'];
  var firstCell = range.split(':')[0];
  var lastCell = (range.split(':')[1]).replace(/[A-Z]/,cellColumnStart);
  workSheet['!ref'] = firstCell+":"+lastCell;
}

function handleWriteFileSelect(evt) { writeExcel(workSheet,last_cell,excelData); workBookFinal = XLSX.write(workBook,{type: 'base64',bookSST: true});

};

function s2ab(s) { var buf = new ArrayBuffer(s.length); var view = new Uint8Array(buf); for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; return buf; }

function handleDownloadFileSelect(evt) {

  saveAs(new Blob([s2ab(atob(workBookFinal))],{type:"application/excel"}), "test.xlsx");

};
selvishah commented 7 years ago

looks like the wrapText property itself is not taking effect. Can someone please check why?

selvishah commented 7 years ago

which version of the main branch is this part of? I was trying to access this directly using the cdjns link https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.4/xlsx.js. Looks like the changes are not part of that? I downloaded the file directly from here and formatting works.