Closed leanesanity closed 4 years ago
Let's start from the top. Can you try:
export const insertData = (file, callback) => {
const fileReader = new FileReader();
fileReader.onload = (event) => {
try {
const { result } = event.target;
const workbook = XLSX.read(result, {
type: 'binary',
});
const firstSheet = workbook.SheetNames[0];
const worksheet = workbook.Sheets[firstSheet];
// Log D4
console.log(worksheet.D4);
// modify value in D4
worksheet.D4.v = 'NEW VALUE from NODE';
const wopts = { bookSST: true };
XLSX.writeFile(workbook, "out.xlsm", wopts);
callback(true); // URL here is use for download
} catch (e) {
console.log(e);
callback(null);
}
};
fileReader.readAsBinaryString(file);
};
If this fails, can you share the original and generated file?
That code ables me to download the file. But it seems that the formats on my file are all gone and macros
What I am trying to do here is just, update some values of some cells. Retaining the same formats of the file. Is it possible ? How to do it? Thank you very much for the help. Really appreciated it
That particular work flow is something we offer as part of our Pro offering.
I am also getting a corrupted excel file. I am using the express JS server and trying to get from AWS MWS. API will return excel but I am not able to get a proper Excel file. Anyone can help me?
const XLSX = require('xlsx');
var ws = XLSX.utils.json_to_sheet(response.data);
var wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws);
var buf = XLSX.write(wb, {bookType:'xlsx', type:'buffer'}); // generate a nodejs buffer
var str = XLSX.write(wb, {bookType:'xlsx', type:'binary'});
XLSX.writeFile(wb, "sheetjs.xlsx");
I fixed the issue by write stream.
const dest = fs.createWriteStream('./sheetjs.xlsx');
response.body.pipe(dest).on('finish', function(){
console.log('done');
});
I have an issue when downloading the file, what I am suppose to do is edit the content of my xlsm file and then download the file. I also tried https://github.com/SheetJS/sheetjs/issues/217 workaround here, but it doesn't work.
My Sample Code :
export const insertData = (file, callback) => { const fileReader = new FileReader(); fileReader.onload = (event) => { try { const { result } = event.target; const workbook = XLSX.read(result, { type: 'binary', }); const firstSheet = workbook.SheetNames[0]; const worksheet = workbook.Sheets[firstSheet]; // modify value in D4 worksheet.D4.v = 'NEW VALUE from NODE';
}; fileReader.readAsBinaryString(file); };
LOG