jarens
10/22/2020, 7:15 PMbattk
10/22/2020, 7:21 PMbattk
10/22/2020, 7:21 PMbattk
10/22/2020, 7:21 PMjarens
10/22/2020, 7:23 PMbattk
10/22/2020, 7:23 PMjarens
10/22/2020, 7:24 PMbattk
10/22/2020, 7:25 PMjarens
10/22/2020, 7:26 PMbattk
10/22/2020, 7:35 PMjarens
10/22/2020, 7:37 PMSteve Cahill
10/22/2020, 7:38 PMjarens
10/22/2020, 7:49 PM/**
* @NApiVersion 2.x
* @NScriptType suitelet
* @NAmdConfig /SuiteScripts/configuration.json
* @Author Jack Arens | National Food Group
*/
define(['N/record', 'N/search', 'N/file', 'N/encode', 'jszip', 'xlsx'],
function (record, search, file, encode, jszip, xlsx) {
function onRequest(options) {
var response = options.response;
var f = file.load({
id: 26779396
});
//Start code from <https://stackoverflow.com/questions/8238407/how-to-parse-excel-xls-file-in-javascript-html5>
var ExcelToJSON = function () {
this.parseExcel = function (file) {
//var reader = new FileReader();
var data = file;
var workbook = XLSX.read(data, {
type: 'file'
});
workbook.SheetNames.forEach(function (sheetName) {
// Here is your object
var XL_row_object = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);
var json_object = JSON.stringify(XL_row_object);
log.debug('JSON OBJ', JSON.parse(json_object));
});
reader.onerror = function (ex) {
log.debug('Error', ex);
};
reader.readAsBinaryString(file);
};
};
var xl2json = new ExcelToJSON();
xl2json.parseExcel(f);
//End code from <https://stackoverflow.com/questions/8238407/how-to-parse-excel-xls-file-in-javascript-html5>
response.write({
output: JSON.stringify('Success')
});
}
return {
onRequest: onRequest
};
});
jarens
10/22/2020, 7:49 PM