I have successfully integrated sheetjs to import excel files into a database. However, I have encountered an issue where it only imports the first 1000 rows of data.
Here is my code: Whenever a user uploads a file using the input field, a worker is created to handle the reading process. Once the reading is complete, the data is sent via ajax to the PHP import script.
$('#input-excel2').change(function(e){
var v=Date.now();
var worker = new Worker("./scripts/parsexlsx2.js?v="+v);
var data= e.target.files[0];
var filename= e.target.files[0].name;
if(filecheck(filename)) {
worker.postMessage(data);
$('#loader2').jqxLoader('open');
worker.onmessage = function(e) {
$.ajax({
type:"POST",
url: "./scripts/import2.php?action=import",
data: {data: e.data, datei: filename},
datatype: "JSON",
success: function(answer) {
$('#eventsPanel2').html(answer);
$("#input-excel2").val("");
getlastuploads();
}
});
worker.terminate();
$('#loader2').jqxLoader('close');
};
} else {
$('#eventsPanel2').html("Die Datei "+filename+ " wurde bereits importiert!");
}
});
This is the actual read script in the worker:
importScripts('../js-xlsx/dist/xlsx.full.min.js');
onmessage=function(msg) {
var reader = new FileReader();
reader.readAsArrayBuffer(msg.data);
reader.onerror = function(e) {
var htmlstr = e.data;
};
reader.onload = function(e) {
var data = new Uint8Array(reader.result); //reader.result;
var wb = XLSX.read(data,{type:'array',cellDates:true, cellNF: false, cellText:false});
var sheetName = wb.SheetNames[0];
var result = XLSX.utils.sheet_to_json(wb.Sheets[sheetName],{header:1,dateNF:'YYYY-MM-DD"T"hh:mm:ss'});
postMessage(result);
};
};