Strange behavior: parse buffer works for small file, not a same file with 2000 more rows data. #604

Closed
opened 2017-03-25 03:34:49 +00:00 by superkang18 · 3 comments
superkang18 commented 2017-03-25 03:34:49 +00:00 (Migrated from github.com)

hi, I am struggling with a very basic excel file. It worked for a small file (2 lines of data on "positions" tab), then it stops working after i added 2000 lines of data rows. I use connect-busboy to parse the uploaded file and get the buffer array, then use the xlsx.read(data) to read the buffer. I attached below code of getting the file stream using busboy and then tries to parse it. Can you please help out ! Many thanks!!
WS_template_small.xlsx
WS_template.xlsx

Step1: get file stream using busboy middleware: then call "getExcelData" after finish

var importFile = function (req) {
var promise = new Promise(function (resolve, reject) {
var busboyObj = new Busboy({ headers: req.headers });
var fileStream = {};
var dataResult = {};
req.pipe(req.busboy);
req.busboy.on('file', function (fieldname, file, filename) {
file.on('data', function (data) {
logging.debug('on....data'+data.length);
dataResult = data;
});
file.on('end', function () {
logging.debug('on....end'+dataResult.length);
});
});
req.busboy.on('finish', function() {
console.log('Done parsing form!'+dataResult.length);
var xlsDataTable = getExcelData(dataResult);
resolve('success');
});

    });
    return promise;
};

Step 2: use getExcelData to parse file stream into excel. Works for WS_template_small, but not for WS_template which has 2000 more lines of rows.

function getExcelData(data) {
//logging.debug('File got ' + data.length + ' bytes');
var workbook = XLSX.read(data);
var sheet_name_list = workbook.SheetNames;
...
...}

Error i got:

default: throw new Error("Unsupported file " + n.join("|"));
	         ^

Error: Unsupported file 223|165|19|18

hi, I am struggling with a very basic excel file. It worked for a small file (2 lines of data on "positions" tab), then it stops working after i added 2000 lines of data rows. I use connect-busboy to parse the uploaded file and get the buffer array, then use the xlsx.read(data) to read the buffer. I attached below code of getting the file stream using busboy and then tries to parse it. Can you please help out ! Many thanks!! [WS_template_small.xlsx](https://github.com/SheetJS/js-xlsx/files/869641/WS_template_small.xlsx) [WS_template.xlsx](https://github.com/SheetJS/js-xlsx/files/869642/WS_template.xlsx) # Step1: get file stream using busboy middleware: then call "getExcelData" after finish var importFile = function (req) { var promise = new Promise(function (resolve, reject) { var busboyObj = new Busboy({ headers: req.headers }); var fileStream = {}; var dataResult = {}; req.pipe(req.busboy); req.busboy.on('file', function (fieldname, file, filename) { file.on('data', function (data) { logging.debug('on....data'+data.length); dataResult = data; }); file.on('end', function () { logging.debug('on....end'+dataResult.length); }); }); req.busboy.on('finish', function() { console.log('Done parsing form!'+dataResult.length); **var xlsDataTable = getExcelData(dataResult);** resolve('success'); }); }); return promise; }; # Step 2: use getExcelData to parse file stream into excel. Works for WS_template_small, but not for WS_template which has 2000 more lines of rows. function getExcelData(data) { //logging.debug('File got ' + data.length + ' bytes'); **var workbook = XLSX.read(data);** var sheet_name_list = workbook.SheetNames; ... ...} # Error i got: default: throw new Error("Unsupported file " + n.join("|")); ^ Error: Unsupported file 223|165|19|18
SheetJSDev commented 2017-03-25 03:44:44 +00:00 (Migrated from github.com)

@superkang18 I'm not familiar with busboy, but can you try writing data to a file in your getExcelData function and seeing if you can open it with Excel? If this works for small files but not for larger files you may need to do some sort of buffering to grab the entire file.

@superkang18 I'm not familiar with `busboy`, but can you try writing `data` to a file in your `getExcelData` function and seeing if you can open it with Excel? If this works for small files but not for larger files you may need to do some sort of buffering to grab the entire file.
superkang18 commented 2017-03-25 03:56:15 +00:00 (Migrated from github.com)

thanks, @SheetJSDev , will take a look from that side.

thanks, @SheetJSDev , will take a look from that side.
superkang18 commented 2017-03-25 04:35:17 +00:00 (Migrated from github.com)

I found the issue, it's nothing to do with xlsx. I need to concatenate the buffer before passing into "read" function. thanks.

I found the issue, it's nothing to do with xlsx. I need to concatenate the buffer before passing into "read" function. thanks.
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#604
No description provided.