This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample2.js
119 lines (106 loc) · 3.68 KB
/
example2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//Dependencias
const xlsx = require( 'node-xlsx');
const fs = require('fs')
const mysql = require('mysql')
//Cierra dependencias
//MYSQL
const connection = mysql.createConnection({
host: 'localhost',
user: 'colo13',
password: '123',
database: 'colo13v'
})
const pool = mysql.createPool({
host: 'localhost',
user: 'colo13',
password: '123',
database: 'colo13v'
})
connection.connect((err) => {if(err) throw err;
console.log('Database conectada')})
//Cerrar MYSQL
//Auxiliares
auxdatos = '';
//Cierra auxiliares
function incertar(){
let insertQuery = 'INSERT INTO miembros (usuario, contrase, membresia) VALUES (?, ?, ?)'
let query = mysql.format(insertQuery,['colo13', 'picadadetomate', 'comun'])
pool.getConnection(function(err, connection){if(err) throw err;
connection.query(query, function(err,result){
if(err) throw err;
console.log(result, 'paso')
connection.release()
})
})
}
function leer(){
pool.getConnection(function(err, connection){if(err) throw err;
connection.query('SELECT * FROM miembros', function(err,result) {if(err) throw err; console.log(result)
console.log(result[0].contrase)
})
connection.release()
})
}
function actualizar(){
pool.getConnection(function(err, connection){if(err) throw err;
let updatequery = 'UPDATE miembros SET usuario = ? WHERE ID = ?';
let query = mysql.format(updatequery,['kkopz', '1'])
connection.query(query, function(err,result) {if(err) throw err; console.log(result)
})
connection.release()
})
}
function creartabla(){
pool.getConnection(function(err, connection){if(err) throw err;
connection.query('CREATE TABLE miembros (ID int NOT NULL AUTO_INCREMENT,usuario varchar(255) NOT NULL,contrase varchar(255),membresia varchar(255),PRIMARY KEY (ID));', function(err,result) {if(err) throw err; console.log(result)})
connection.release()
})
}
function borrardato(){
pool.getConnection(function(err, connection){if(err) throw err;
let removequery = 'DELETE FROM miembros WHERE ID = ?';
let query = mysql.format(removequery,['1'])
connection.query(query, function(err,result) {if(err) throw err; console.log(result)
})
connection.release()
})
}
function importar(ruta){
usuariosimportar = []
contraseñasimportar = []
aux = xlsx.parse(ruta)
console.log(aux[0].data[0][0],':')
for(i=1;i< aux[0].data.length;i++){
if(aux[0].data[i][0] === undefined || aux[0].data[i][0]===[]) continue;
console.log(aux[0].data[i][0],aux[0].data[0][2]+ ': ', aux[0].data[i][2])
usuariosimportar.push(aux[0].data[i][0])
contraseñasimportar.push(aux[0].data[i][2])
}
// console.log(usuariosimportar)
// console.log(contraseñasimportar)
// console.log(aux[0].data)
exportar(usuariosimportar,contraseñasimportar)
// fs.writeFileSync('./exportadoff.xlsx', datoaexp , 'binary');
}
function exportar(usuarios,contraseñas){
data = []
data.push([' Usuarios ','ID',' Contraseñas '])
data.push([])
for(k=0;k<usuarios.length;k++){data.push([usuarios[k],k,contraseñas[k]])}
console.log(data)
const sheetOptions = {'!cols': [{wch: 30}, {wch: 6}, {wch: 30}, {wch: 7}]};
datoaexp = xlsx.build([{name: 'cuentas', data: data}], {sheetOptions})
fs.writeFileSync('./cuentas.xlsx', datoaexp , 'binary');
}
function prueba(){
const rowAverage = [[{t: 'n', z: 10, f: '=AVERAGE(2:2)'}], [1, 2, 3]];
var buffer = xlsx.build([{name: 'Average Formula', data: rowAverage}]);
fs.writeFileSync('./prueba.xlsx', buffer , 'binary');
}
importar(`./importarexcel.xlsx`)
// prueba()
// creartabla()
// incertar()
// leer()
// actualizar()
// borrardato()