mirror of
https://github.com/cheveguerra/botGuna.git
synced 2026-04-17 19:37:07 +00:00
NoInitial2
This commit is contained in:
57
Excel.js
Normal file
57
Excel.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
const ExcelJS = require('exceljs');
|
||||||
|
const fs = require('fs')
|
||||||
|
const workbook = new ExcelJS.Workbook();
|
||||||
|
|
||||||
|
const guardaXLSDatos = async (nombre, edad, sexo) => {
|
||||||
|
// read from a file
|
||||||
|
await workbook.xlsx.readFile('./bot.xlsx');
|
||||||
|
// fetch sheet by name
|
||||||
|
const worksheet = workbook.getWorksheet('Bot');
|
||||||
|
const rowValues = [];
|
||||||
|
rowValues[1] = nombre;
|
||||||
|
rowValues[2] = edad;
|
||||||
|
rowValues[3] = sexo;
|
||||||
|
worksheet.addRow(rowValues);
|
||||||
|
await workbook.xlsx.writeFile('./bot.xlsx');
|
||||||
|
console.log(rowValues)
|
||||||
|
console.log("Guardamos XLS")
|
||||||
|
}
|
||||||
|
|
||||||
|
const leeXLSDatos = async (srchStr) => {
|
||||||
|
// read from a file
|
||||||
|
await workbook.xlsx.readFile('./bot.xlsx');
|
||||||
|
// fetch sheet by name
|
||||||
|
const worksheet = workbook.getWorksheet('Bot');
|
||||||
|
console.log(worksheet.rowCount)
|
||||||
|
let colNombre = worksheet.getColumn(1).values
|
||||||
|
let cont = 0
|
||||||
|
let encontrado = 0
|
||||||
|
let row
|
||||||
|
let res = []
|
||||||
|
// while (cont <= worksheet.rowCount && encontrado == 0) { // Ocupamos while en lugar de forEach para que deje de buscar en cuanto encuentre el resultado.
|
||||||
|
// console.log(cont, colNombre[cont], srchStr)
|
||||||
|
// if(colNombre[cont] === srchStr) {
|
||||||
|
// row = worksheet.getRow(cont);
|
||||||
|
// res['nombre'] = row.getCell(1).value
|
||||||
|
// res['edad'] = row.getCell(2).value
|
||||||
|
// res['sexo'] = row.getCell(3).value
|
||||||
|
// encontrado = colNombre[cont]
|
||||||
|
// }
|
||||||
|
// cont++;
|
||||||
|
// }
|
||||||
|
// console.log("RES=", res)
|
||||||
|
// for (let index = 0; index < worksheet.rowCount; index++) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// }
|
||||||
|
let rows = []
|
||||||
|
worksheet.eachRow(function(row, rowNumber) {
|
||||||
|
// console.log('Row ' + rowNumber + ' = ' + JSON.stringify(row.values));
|
||||||
|
rows[rowNumber-1]={'nombre':row.getCell(1).value, 'carnet':row.getCell(4).value, 'factura':row.getCell(5).value, 'prefijo':row.getCell(6).value}
|
||||||
|
});
|
||||||
|
// console.log(rows)
|
||||||
|
return rows
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {guardaXLSDatos, leeXLSDatos};
|
||||||
18
package-lock.json
generated
18
package-lock.json
generated
@@ -797,9 +797,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/ast-types/node_modules/tslib": {
|
"node_modules/ast-types/node_modules/tslib": {
|
||||||
"version": "2.4.1",
|
"version": "2.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz",
|
||||||
"integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==",
|
"integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/async": {
|
"node_modules/async": {
|
||||||
@@ -1246,9 +1246,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/content-type": {
|
"node_modules/content-type": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
|
||||||
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==",
|
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
@@ -4793,9 +4793,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/systeminformation": {
|
"node_modules/systeminformation": {
|
||||||
"version": "5.17.4",
|
"version": "5.17.7",
|
||||||
"resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-5.17.4.tgz",
|
"resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-5.17.7.tgz",
|
||||||
"integrity": "sha512-mEiIYrw7X5ABX8tJUgzbumQAuFQxNyHdZDz6+UtwNKUbKgIoZqLtug2z1spFB/LiXZne5tdPBJOlvVckbvfhiQ==",
|
"integrity": "sha512-0eQA5IkDlP4njQm9b5LvApCXaD52zFLfu+Xte1VdfaMChu4DxCSCmCjr/jAQK63gtHJ63x5gstCW5y3oWh9n+A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
|
|||||||
Reference in New Issue
Block a user