NoInitial2

This commit is contained in:
2023-01-29 16:09:15 -06:00
parent ff05e96cc6
commit 3b2106fef8
3 changed files with 66 additions and 9 deletions

57
Excel.js Normal file
View 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};

BIN
bot.xlsx Normal file

Binary file not shown.

18
package-lock.json generated
View File

@@ -797,9 +797,9 @@
}
},
"node_modules/ast-types/node_modules/tslib": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz",
"integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==",
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz",
"integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==",
"dev": true
},
"node_modules/async": {
@@ -1246,9 +1246,9 @@
}
},
"node_modules/content-type": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==",
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
"engines": {
"node": ">= 0.6"
}
@@ -4793,9 +4793,9 @@
}
},
"node_modules/systeminformation": {
"version": "5.17.4",
"resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-5.17.4.tgz",
"integrity": "sha512-mEiIYrw7X5ABX8tJUgzbumQAuFQxNyHdZDz6+UtwNKUbKgIoZqLtug2z1spFB/LiXZne5tdPBJOlvVckbvfhiQ==",
"version": "5.17.7",
"resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-5.17.7.tgz",
"integrity": "sha512-0eQA5IkDlP4njQm9b5LvApCXaD52zFLfu+Xte1VdfaMChu4DxCSCmCjr/jAQK63gtHJ63x5gstCW5y3oWh9n+A==",
"dev": true,
"optional": true,
"os": [