Files
puppeteerjs/src/excel/ExcelUtil.js
T

37 lines
1.3 KiB
JavaScript

const xlsx = require('node-xlsx');
const ContactPojo = require("../models/ContactPojo");
class ExcelUtil {
readContacts(pathToExcelFile) {
let workSheetsFromFile = xlsx.parse(pathToExcelFile);
let contactList = [];
workSheetsFromFile[0].data.forEach(
(info, index, list) => {
if (index > 0 && info.length > 0) {
let name = info[0].trim().split(" ")
let firstName = name[1];
let lastName = name[0];
let phoneNumber = info[1];
let passportNumber = info[2];
let mail = info[3];
let store = info[4];
if (store === undefined || store.length === 0) {
store = "random"
}
let serial = info[5];
let ipCountry = info[6];
if (ipCountry === undefined || ipCountry.length === 0) {
ipCountry = "FR"
}
let newContact = new ContactPojo(phoneNumber, passportNumber, lastName, firstName, mail, store, ipCountry, serial);
contactList.push(newContact);
}
}
)
return contactList;
}
}
module.exports = ExcelUtil